1、1、Java语言基础实验目的和要求(1)掌握标识符的定义规则。(2)掌握表达式的组成。(3)掌握各种数据类型及其使用方法。(4)理解定义变量的作用,掌握定义变量的方法。(5)掌握各种运算符的使用及其优先级控制。实验内容(1) 掌握变量定义与数据类型。(2) 掌握算术运算。(3) 掌握关系运算与逻辑运算。2、Java语言程序设计基础(1)掌握分支语句的使用。(2)掌握循环语句的使用(3)了解continue语句和break语句的使用。(1) 分别使用if-else-if语句和switch语句编程,确定某一月在哪个季节。(2) 分别使用while、do-while和for语句编程,求1100的和。
2、(3) 使用continue语句实现:将100300之间的不能被3整除的数输出。(4) 使用break语句实现记数:从1100,当数到78时程序终止。3、类与对象(1)掌握类的声明。(2)掌握对象的创建。(3)掌握方法的定义和调用。(5)掌握构造函数的使用。(1)编程创建一个Box类,在其中定义三个变量表示一个立方体的长、宽和高,再定义一个方法setDemo对这三个变量进行初始化,然后定义一个方法求立方体的体积。创建一个对象,求给定尺寸的立方体的体积。(2)将上题的方法setDemo改用构造函数实现初始化。4、继承与多态(1)掌握类的继承方法。(2)掌握变量的继承和覆盖。(3)掌握方法的继承、
3、重载和覆盖。(4)了解接口的实现方法。(1)理解成员变量的继承与隐藏。(2)运行程序,理解方法的继承。(3)运行程序,理解方法的重载。(4)运行程序,理解方法的覆盖。5、常用基础类库与工具类库(1)掌握Math类的使用。(2)掌握String类和StringBuffer类的使用(3)掌握Java Application命令行参数的使用。(1)利用下面的关键代码编写一个完整的程序,理解Math类的使用。(2)利用关键代码编写一个完整的程序,理解String类的使用。(3)利用关键代码编写一个完整的程序,理解StringBuffer类的使用。(4)使用Java Aplication的命令行参数读入
4、两个数据,计算它们的和,然后将和输出。如果参数的数目不足,显示相应提示信息并退出程序的执行。实验报告班级:姓名:学号:实验一:Java语言基础实验内容:程序框图程序源码实验二:Java语言程序设计基础import java.util.Scanner;public class ad public static void main (String args) Scanner s=new Scanner(System.in); System.out.print(请输入月份); String season=; int month=s.nextInt(); switch(month) case 1: c
5、ase 2: case 3: season=春季 break; case 4: case 5: case 6: season=夏季 break; case 7: case 8: case 9:秋季 case 10: case 11: case 12:冬季 default: season=请输入1-12的数字 break; System.out.println(season); public class assd public static void main (String args) int j=0; for(int i=0;i100;i+) j+=i; System.out.println
6、(j); for(int i=100;=300; if(i%3=0)continue; System.out.print(i+t System.out.println(); if(i=78)break; System.out.println(i+实验三:类与对象public class lib04 public static void main(String args) Box b1=new Box(); b1.setDemo(12.34,23.45,34.56); System.out.println(体积=+b1.GetV(); Box b2=new Box(12.34,23.45,34.
7、56);+b2.GetV();class Box private double length; private double width; private double height; public void setDemo(double l,double w,double h) this.length=l; this.width=w; this.height=h; public Box() public Box(double l,double w,double h) public double GetV() return height*length*width;实验四:继承与多态packag
8、e as;public interface Animals public void food(); void walk1();public void walk(); class Person implements Animals private String name; public String getName() return name; public void setName(String name) this.name = name; public int getAge() return age; public void setAge(int age) this.age = age;
9、private int age;public void food() System.out.println(杂食public void walk()直立行走public void walk1() class Bird implements Animals public void food()虫子 public void walk()飞翔 public void walk(String name) System.out.println(name+可以飞翔 public void walk1() public class lib05 Animals a=new Person(); a.food()
10、; a.walk(); Bird b=new Bird(); b.food(); b.walk(); b.walk(Ivan实验五:常用基础类库与工具类库 int a=100; System.out.println(Math.abs(a); a=1234; System.out.println(Math.sqrt(a); String str1=xxx str1+=yyy System.out.println(str1); StringBuilder str2=new StringBuilder(); str2.append(goodgod System.out.println(str2); if(args.length=2) int x=Integer.parseInt(args0); int y=Integer.parseInt(args1); System.out.println(x+y=+(x+y); else参数数量不足
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1