1、3、编写使用不同循环结构结构的程序。实验内容:public class DataTypes public static void main(String args) byte b=127; short s=32767; int i=2147483647; long l=9223372036l;/为什么long表示的数比Int还小? char c=c; float f=1.23F; double d=0.9E-3; boolean bool=true; System.out.println( b=+b); s=+s); i=+i); l=+l); c=+c); f=+f); d=+d); boo
2、l=+bool); /public class Testif boolean leap; int year=2014; if(year%4=0&year%100!=0)|(year%400=0)/ System.out.println(year+年是闰年); else年不是闰年 /方法二/ year=2008; if(year%4!=0) leap=false; else if(year%100! leap=true; else if(year%400! else if(leap=true) System.out.println(year+ /方法三/ year=2050; if(year%4
3、=0) if(year%100=0) if(year%400=0) leap=true; else leap=false; else leap=false; /使用switch语句/1.编写程序用Switch语句实现从键盘上都1,2,3时,屏幕提示不同的信息import java.io.*;class SwitchTest public static void main(String args) throw IOException char a;Enter a number from 1-3: a=(char)System.in.read(); switch(a) case 1: System
4、.out.println(win a Car!break; case 2picked the goat3get to keep your100! default:System.out.println(entry/for循环语句class ForTest public static void main(String args)throws IOException int fahr,cels; System.out.println(Celsius Fahrenheit for(cels=0;cels=100;cels+=5) fahr=cels*9/5+32; System.out.println
5、(cels+ +fahr); char a; outer:/this is the lable for the outer loop for(int i=0;i10;i+) for(int j=0;jj+) a=(char)System.in.read(); if(a=b) break outer; continue outer;/while循环语句/class WhileTest public static void main(String args)throws IOException char ch;按1/2/3数字可获大奖!按空格键后回车可退出循环操作 while(ch=(char)S
6、ystem.in.read()!= System.in.skip(2);/跳过回车键 switch(ch) case恭喜你获得大奖,一辆汽车不错呀,你得到一台笔记本电脑 case 没白来,你得到一台冰箱 default: System.out.println(真不兴,你没有奖品!下次再来 /多重循环public class Mul99 public static void main(String args) int i,j, n=9; System.out.print( * | for(i=1;n-| for(i=1;- System.out.println();=n;i+) System.o
7、ut.print(+i+ | for(j=1;=i;j+)+i*j);实验感想: 实验二 面向对象编程试验通过编程和上机实验理解Java语言是如何体现面向对象编程基 本思想,熟悉类的封装方法以及如何创建类和对象,熟悉成员变量和成员方法的 特性,熟悉类的继承性和多态性的作用,熟悉包、接口的使用方法,掌握OOP 方式进行程序设计的方法。1、编写程序实现类的定义和使用。2、编写不同成员和不同成员方法修饰方法的程序。3、编写体现类的继承性(成员变量、成员方法、成员变量隐藏)的程序 和多态性(成员方法重载、构造方法重载)的程序。4、编写接口的定义和使用的程序。5、编写包的定义和使用的程序。实验内容-1. 日期类输出当前日期public class Dateprivate int year,month,day;/private static thisYear; public Date(int y,int m,int d) this.year=y; this.month=m; this.day=d; public void read(int y,int
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1