欢迎来到天天文库
浏览记录
ID:40566086
大小:106.50 KB
页数:16页
时间:2019-08-04
《Java学生成绩查询系统》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Chap2实践2-1classEx2_1{publicstaticvoidmain(String[]args){floatsum=0.0f,count=1.0f;for(inti=1;i<=20;++i){count=1.0f;for(intj=1;j<=i;++j)count*=j;sum+=count;}System.out.println("1+2!+3!+...+20!的值为:"+sum);}}实践2-2publicclassEx2_2{publicstaticvoidmain(String[]args){System.out.println
2、("**菲波拉挈数列的前20个数为:**");longf1=1,f2=1;for(inti=1;i<=10;i++){System.out.print(f1+""+f2+"");if(i%2==0){System.out.println();}f1=f1+f2;f2=f2+f1;}}}Chap3实践3-1publicclassStudent{staticStringname="张三";staticintage;publicStudent(){age=18;}publicstaticvoidmain(Stringargs[]){System.out.p
3、rintln("姓名:"+name+",年龄:"+age);}}实践3-2classPeople{Stringname;People(Stringname){this.name=name;//对成员变量name初始化}}classStudentextendsPeople{StringstuID;Student(Stringname,StringstuID){super(name);//对继承自父类的成员变量name初始化this.stuID=stuID;//对成员变量stuID初始化}}publicclassPeopleDemo{publicstat
4、icvoidmain(Stringarg[]){Studentstu=newStudent("张三","20080601");//定义对象System.out.println(stu.name+""+stu.stuID);//输出对象的姓名和学号}}Chap4实践4-1publicclassEx4_1{Stringstr;publicEx4_1(Stringstr){this.str=str;}intgetlength(){return(str.length());}publicstaticvoidmain(String[]args){Ex4_1te
5、st=newEx4_1("Hello");System.out.println("字符串是:"+test.str+"长度为:"+test.getlength());}}实践4-2importjava.util.*;importjava.io.*;publicclassEx4_2{publicstaticvoidmain(String[]args){Stringstr1=newString();Stringstr2=newString();charch;Scannerreader=newScanner(System.in);System.out.pri
6、ntln("输入字符串:");str1=reader.next();//输入字符串System.out.println("输入要删除的字符:");str2=reader.next();//输入穿要删除的字符,以字符串的形式输入ch=str2.charAt(0);//将字符串转换为字符str2=str1.replace(ch,'');//用空格替代指定字符System.out.println("删除字符后的字符串"+str2);}}Chap5实践5-1publicclassEx5_1{publicstaticvoidmain(String[]args)
7、{try{intnum[]=newint[10];System.out.println("num[10]is"+num[10]);}catch(Exceptionex){System.out.println("Exception");}catch(RuntimeExceptionex){System.out.println("RuntimeException");}catch(ArithmeticExceptionex){System.out.println("ArithmeticException");}}}实践5-2publicclassEx5_
8、2{staticdoublecal(doublea,doubleb)throwsIllegalArgumen
此文档下载收益归作者所有