JAVA上机实验期末试题

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

题目1:

package test;

import java.util.Scanner;

public class scanner

{

public static void main(String args[])

{

int x1,x2,x3,x4,x5,sum;

Scanner sc=new Scanner(System.in);

int n=sc.nextInt();

x1=n/10000;

x2=n/1000-10*x1;

x5=n%10;

x4=(n%100-x5)/10;

x3=(n/100)%10;

sum=x1+x2+x3+x4+x5;

System.out.println(x1+"+"+x2+"+"+x3+"+"+x4+"+"+x5+"="+sum);

}

}

题目2:

package test;

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.FileReader;

import java.io.FileWriter;

public class j_Write

{

public static void main(String args[]) throws Exception

{

int s[]={21,30,10,20,44,65};

BufferedWriter bw=new BufferedWriter(new

FileWriter("Dest.txt"));

BufferedReader br=new BufferedReader(new

FileReader("Dest.txt"));

for(int i=0;i<6;i++)

{

bw.write(String.valueOf(s[i]));

bw.write(",");

bw.flush();

}

bw.close();

int i = 0;

String l=br.readLine();

String t[]=l.split(",");

for(i=5;i>=0;i--)

{

System.out.print(t[i]+" ");

}

br.close();

}

}

题目3:

package test;

import java.awt.Container;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

public class test3 extends JFrame implements ActionListener {

public test3()

{

Container c=getContentPane();

setTitle("按钮例子");

JButton but=new JButton("退出按钮");

but.addActionListener( this);

c.add(but);

pack();

setLocationRelativeTo(null);

}

public static void main(String args[])

{

test3 hss=new test3();

hss.setVisible(true);

}

public void actionPerformed(ActionEvent e)

{

System.exit(0);

}

}

题目4:

package test;

public class Student

{

int sNO,sAge;

double sJava;

String sName,sSex;

public Student(int sNO,String sName,int sAge ,double sJava,String sSex)

{

this.sNO=sNO;

this.sName=sName;

this.sAge=sAge;

this.sJava=sJava;

this.sSex=sSex;

}

public int getNo()

{

return sNO;

}

public String getName()

{

return sName;

}

public int getAge()

{

return sNO;

}

public double getJava()

{

return sJava;

}

public String getSex()

{

return sSex;

}

public static void main(String args[])

{

double sum,average,max,min;

Student s1=new Student(1,"A",18,80,"男");

Student s2=new Student(2,"B",18,90,"女");

Student s3=new Student(3,"C",18,85,"男");

Student s4=new Student(4,"D",18,88,"男");

Student s5=new Student(5,"E",18,98,"女");

System.out.println("学号"+" 姓名 "+" 年龄"+" 成绩"+" 性别");

System.out.println(" "+s1.getNo()+" "+s1.getName()+"

"+s1.getAge()+" "+s1.getJava()+" "+s1.getSex());

System.out.println(" "+s2.getNo()+" "+s2.getName()+"

"+s2.getAge()+" "+s2.getJava()+" "+s2.getSex());

System.out.println(" "+s3.getNo()+" "+s3.getName()+"

"+s3.getAge()+" "+s3.getJava()+" "+s3.getSex());

System.out.println(" "+s4.getNo()+" "+s4.getName()+"

"+s4.getAge()+" "+s4.getJava()+" "+s4.getSex());

System.out.println(" "+s5.getNo()+" "+s5.getName()+"

"+s5.getAge()+" "+s5.getJava()+" "+s5.getSex());

sum=s1.getJava()+s2.getJava()+s3.getJava()+s4.getJava()+s5.getJava(); average=sum/5;

相关文档
最新文档