欢迎来到天天文库
浏览记录
ID:6326886
大小:115.50 KB
页数:24页
时间:2018-01-10
《java语言实验指导书》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、实验1Java语言基础训练1.1实验目的通过简单的输入输出程序,熟悉Java编程环境,掌握Java程序结构,为进一步学习Java语言的面向对象特征奠定基础。1.2实验要求1.熟悉JCreator或Eclipse软件安装使用方法。2.掌握编写与运行Java程序的方法。3.熟悉Java语言的概貌,其中包括数据类型、变量、数组和程序控制结构。4.掌握JDK5.0的输入方法。1.3实验内容1.3.1一个简单的问候程序/*Thisisthefirstsampleprogram*/publicclassHelloWorld{
2、publicstaticvoidmain(String[]args){System.out.println("'Hello,World!");}}1.3.2输入输出程序/**24@适合于JDK5.0或更高的版本*/importjava.util.*;//适合于JDK5.0或更高的版本,以下同publicclassInputTest{publicstaticvoidmain(String[]args){Scannerin=newScanner(System.in);//适合于JDK5.0或更高的版本,以下同//ge
3、tfirstinputSystem.out.print("Whatisyourname?");Stringname=in.nextLine();//适合于JDK5.0或更高的版本,以下同//getsecondinputSystem.out.print("Howoldareyou?");intage=in.nextInt();//适合于JDK5.0或更高的版本,以下同//displayoutputonconsoleSystem.out.println("Hello,"+name+".Nextyear,you'llb
4、e"+(age+1));}}1.3.3求100个整数的和importjava.util.*;publicclassArrayOfStringsDemo{publicstaticvoidmain(String[]args){int[]a=newint[100];Scannerin=newScanner(System.in);intk;for(inti=0;i5、um=0;for(inti=0;i6、继承性的程序。3.编写体现类的多态性的程序。2.3实验内容2.3.1用户自定义类importjava.util.*;publicclassEmployeeTest{publicstaticvoidmain(String[]args){//fillthestaffarraywiththreeEmployeeobjectsEmployee[]staff=newEmployee[3];staff[0]=newEmployee("CarlCracker",75000,1987,12,15);staff[1]=newEmp7、loyee("HarryHacker",50000,1989,10,1);staff[2]=newEmployee("TonyTester",40000,1990,3,15);//raiseeveryone'ssalaryby5%for(inti=0;i8、println("name="+staff[i].getName()+",salary="+staff[i].getSalary()+",hireDay="+staff[i].getHireDay());}}}classEmployee{publicEmployee(Stringn,doubles,intyear,intmonth,intday){name=n;salar
5、um=0;for(inti=0;i6、继承性的程序。3.编写体现类的多态性的程序。2.3实验内容2.3.1用户自定义类importjava.util.*;publicclassEmployeeTest{publicstaticvoidmain(String[]args){//fillthestaffarraywiththreeEmployeeobjectsEmployee[]staff=newEmployee[3];staff[0]=newEmployee("CarlCracker",75000,1987,12,15);staff[1]=newEmp7、loyee("HarryHacker",50000,1989,10,1);staff[2]=newEmployee("TonyTester",40000,1990,3,15);//raiseeveryone'ssalaryby5%for(inti=0;i8、println("name="+staff[i].getName()+",salary="+staff[i].getSalary()+",hireDay="+staff[i].getHireDay());}}}classEmployee{publicEmployee(Stringn,doubles,intyear,intmonth,intday){name=n;salar
6、继承性的程序。3.编写体现类的多态性的程序。2.3实验内容2.3.1用户自定义类importjava.util.*;publicclassEmployeeTest{publicstaticvoidmain(String[]args){//fillthestaffarraywiththreeEmployeeobjectsEmployee[]staff=newEmployee[3];staff[0]=newEmployee("CarlCracker",75000,1987,12,15);staff[1]=newEmp
7、loyee("HarryHacker",50000,1989,10,1);staff[2]=newEmployee("TonyTester",40000,1990,3,15);//raiseeveryone'ssalaryby5%for(inti=0;i8、println("name="+staff[i].getName()+",salary="+staff[i].getSalary()+",hireDay="+staff[i].getHireDay());}}}classEmployee{publicEmployee(Stringn,doubles,intyear,intmonth,intday){name=n;salar
8、println("name="+staff[i].getName()+",salary="+staff[i].getSalary()+",hireDay="+staff[i].getHireDay());}}}classEmployee{publicEmployee(Stringn,doubles,intyear,intmonth,intday){name=n;salar
此文档下载收益归作者所有