资源描述:
《JAVA上机实验期末试题》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、题目1:packagetest;importjava.util.Scanner;publicclassscanner{publicstaticvoidmain(Stringargs[]){intx1,x2,x3,x4,x5,sum;Scannersc=newScanner(System.in);intn=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+"
2、+"+x3+"+"+x4+"+"+x5+"="+sum);}}题目2:packagetest;importjava.io.BufferedReader;importjava.io.BufferedWriter;importjava.io.FileReader;importjava.io.FileWriter;publicclassj_Write{publicstaticvoidmain(Stringargs[])throwsException{ints[]={21,30,10,20,44,65};BufferedWriterbw=newBufferedWr
3、iter(newFileWriter("Dest.txt"));BufferedReaderbr=newBufferedReader(newFileReader("Dest.txt"));for(inti=0;i<6;i++){bw.write(String.valueOf(s[i]));bw.write(",");bw.flush();}bw.close();inti=0;Stringl=br.readLine();Stringt[]=l.split(",");for(i=5;i>=0;i--){System.out.print(t[i]+"");}br
4、.close();}}题目3:packagetest;importjava.awt.Container;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjavax.swing.JButton;importjavax.swing.JFrame;publicclasstest3extendsJFrameimplementsActionListener{publictest3(){Containerc=getContentPane();setTitle("按钮例
5、子");JButtonbut=newJButton("退出按钮");but.addActionListener(this);c.add(but);pack();setLocationRelativeTo(null);}publicstaticvoidmain(Stringargs[]){test3hss=newtest3();hss.setVisible(true);}publicvoidactionPerformed(ActionEvente){System.exit(0);}}题目4:packagetest;publicclassStudent{int
6、sNO,sAge;doublesJava;StringsName,sSex;publicStudent(intsNO,StringsName,intsAge,doublesJava,StringsSex){this.sNO=sNO;this.sName=sName;this.sAge=sAge;this.sJava=sJava;this.sSex=sSex;}publicintgetNo(){returnsNO;}publicStringgetName(){returnsName;}publicintgetAge(){returnsNO;}publicdo
7、ublegetJava(){returnsJava;}publicStringgetSex(){returnsSex;}publicstaticvoidmain(Stringargs[]){doublesum,average,max,min;Students1=newStudent(1,"A",18,80,"男");Students2=newStudent(2,"B",18,90,"女");Students3=newStudent(3,"C",18,85,"男");Students4=newStudent(4,"D",18,88,"男");Students
8、5=newStudent(5,"E",18,98,"女");Sys