第一章:
1.编写类College,College中有一个方法init(),显示“威海职业学院”,编写类School,调用init()方法,在屏幕上显示3行“威海职业学院”。 public class College{ public void init(){
System.out.println(\威海职业学院\} }
public class School{
public static void main(String a[]){ College c1=new College (); for (int i=0;i<3;i++){ c1.init (); } } } 第二章:
1、自定义类Days及其方法dayInmonth( )。该方法的功能是返回用户输入月份的天数(二月份就按28天计算)。例如用户输入3,则该方法将返回值31;用户输入4,则该方法将返回值30。通过main()方法将返回值显示出来。 class Days{
staticint dayInmonth(int a){ int s=31; switch(a)
{case 2: s=28;break;
case 4: case 6: case 9: case 11: s=30; } return s; }
public static void main(String [] args){ int a=Integer.parseInt(args[0]); int b=dayInmonth(a);
System.out.println(a+\月有\天\} }
第三章:
1.编写程序计算12+22+32+42+……+972+982+992+1002的值,输出 class Qiuhe{ static int sum=0; public static int cal(){ for (int i=1;i<=100;i++){ sum+=i*i; }
return sum; }
public static void main(String [] args){ System.out.println(\计算结果为\
} }
2..打印输出10行杨晖三角形
class yanghui {
public static void main (String args[]) {
int i,j;
int yhlevel=10; int yanghui[][];
System.out.println(\杨晖三角形:\
yanghui=new int[yhlevel][]; for(i=0;i yanghui[0][0]=1; for (i=1; i yanghui[i][0]=1; for(j=1;j yanghui[i][j]=yanghui[i-1][j-1]+yanghui[i-1][j]; yanghui[i][yanghui[i].length-1]=1; } for (i=0; i for(j=0;j 输出结果是: 杨晖三角形: 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 1 7 21 35 35 21 7 1 1 8 28 56 70 56 28 8 1 1 9 36 84 126 126 84 36 9 1 第四章: 1.自定义一数组并对数组中每个元素赋值,然后按逆序输出. 2.编写一个程序用选择法对数组a[]={20,10,50,40,30,70,60,80,90,100}进行由大到小的排序。 import java.io.*; ??public class ArrayTest{ ?? public static void main(String args[]){ ?? int i; ?? int a[] = new int[5]; ?? for(i=0;i<5;i++) ?? a[i]=i; ?? for( i=a.Length-1 ;i>=0;i- -) ?? System.out.println(\ ?? } ??} 2. import java.io.*; public class SelectSort { public static void main(String args[]) { int a[]={20,10,50,40,30,70,60,80,90,100}; int temp; for (int i=0; i if (a[i] for (int k=0;k System.out.println(\ } } } 第五章: 1.设计一个长方形类,成员变量包括长和宽。类中有计算面积和周长的方法,并有相应的set方法和get方法设置和获得长和宽。编写测试类测试是否达到预定功能。要求使用自定义的包。 2.设计雇员Employee类,记录雇员的情况,包括姓名、年薪、受雇时间,要求定义MyDate类作为受雇时间,其中包括工作的年、月、日,并用相应的方法对Employee类进行设置。编写测试类测试Employee类。要求使用自己的包。 3 根据下面的要求编程实现复数类ComplexNumber。 (1)复数类ComplexNumber的属性 ·m_dRealPart实部,代表复数的实数部分。 ·m_dlmaginPart虚部,代表复数的虚数部分。