1.输出“Hello Java” Public class HelloJava
{Public static void main(string[] args) {system.out.println(“Hello Java”);}}
2.圆球体积为4/3пr3
,求圆球体积 Public class square
{public static void main(string args[]) {double r=0,v=0;
r=Double.parseDouble(args[0]); v=4*3.1415/3*r*r*r;
system.out.println(“体积为:”+v);}} 3.利用if嵌套完成相同的功能 If(grade==6||grade==7) {a=11;b=22;}
Else if(grade==5) {a=33;b=44;} Else {a=55;}
4.将百分制成绩转换为5级制成绩 Public class classificatcion
{public static void main(string args[]) {char level;
Int grade=integer.parseint(args[0]); Int num=grade/10; Switch(num) {case 6:
Level=’D’;break; case 7:
Level=’C’;break; case 8:
Level=’B’;break; case 9:
Level=’A’;break; case 10:
Level=’A’;break; Default:
Level=’E’;} system.out.println
(“该生成绩为:”+level);}} 5.利用for语句,形成如下图形 * ** *** **** *****
Public class format
{Public static void main(string args[]) {int i,j;
For(j=1;j<=i;j++)
System.out.print(“*”); System.out.print(“\n”);}}} 6.利用while,计算2+4+6+...+100 Public class sumofeven
{Public static void main(string args[]) {int i=2,sum=0; While(i<=100) {sun+=i; i+=2;}
System.out.println(“结果为:”+sum);}} 7.利用for,计算1+3+5+...+99 Public class sumofodd
{Public static void main(string args[]) {int i,sum=0;
For(i=1;i<100;i=i+2) {sun+=i;}
System.out.println(“结果为:”+sum);}} 8.利用do...while,计算1!+2!+...+100! Public class factorial
{Public static void main(string args[]) {int i=1;
Double n=1,sum=0; Do
{n=n*i;sum=sum+n;i++;}whlie(i<=100); System.out.println(“结果为:”+sum);}} 9.绳长3000m,每天减去一半,要几天绳子长度会短于5m?
Public class rope
{Public static void main(string args[]) {int daycount=0;
Float rope_length=3000; Do
{rope_length=rope_length/2;daycount++; }while(rope_length>=5); System.out.println
(“需要时间为:”+daycount+“天”);}} 10.求所有水仙花数
Public class Narcissus
{Public static void main(string args[]) {int i,j,k,n; i=j=k=0; For(n=100;n<1000;n++)
{i=n/100; j=n/10-i*10; k=n%10; If(n==i*i*i+j*j*j+k*k*k)
System.out.println(n+“”);}}}
1
11.地球半径6400km,一人9.8s跑了100m,跑地球一圈需要几天
Public class runaroungtheearth
{Public static void main(string args[]) {double s,meterPerDay,daycount=0; Long r=6400000; S=3.1415*2*r;
Meterperday=24*60*60*100/9.8; Daycount=s/meterperday;
System.out.println(“需要天数为:”
+daycount);}} 12.判断素数
Public class prime
{Public static void testprime(int m) {boolean isPrime=ture; For(int i=2;i<m;i++) If(m%i==0)
{isPrime==false; break;} If(isPrime)
System.out.println(“True”); Else
System.out.println(“False”);} Public static void main(string args[]) {if(args.length!=1)
{ System.out.println(“输入格式错误!请按照此格式输入:java Prime m”); System.exit(0);}
Int number=Integer.parseInt(args[0]); testPrime(number);}}
13.计算1-1/2+1/3-1/4+1/5-1/6+...-1/50 Public class series
{Public static double calculateNum() {int sign=-1;
Double under=1.0,sum=1.0,term; For(int i=2;i<=50;i++) {under=i;
Term=sign/under; Sun=sum+term; Sign=-sian; }return sum;
}public static void main(String args[]) {system.out.println
(“结果为:”+calculateNum());}}
2
14.利用阶乘计算1!+2!+...+10! Public class factorial
{public static int factor(int m) {if(m<=1) return 1;
Else return m*factor(m-1);}
Public static void main(string args[]) {long sum=0;
For(int i=1;i<=10;i++)
Sum=sum+factor(i);
System.out.println(“结果为:”+sum);}} 15.判断一个3位数是否为水仙花数 Public class AsphodelNum {public static boolean isAsphodelNum(int m) {int i,j,k; i=m/100; j=m/10%10; k=m%10; If(m==i*i*i+j*j*j+k*k*k)
Return true;
Else return false;}
Public static void main(string args[]) {if(args.length!=1)
{System.out.println(“输入格式错误!请按照此格式输入:java AsphodelNum m”); System.exit(0);}
Int num=Integer.parseInt(args[0]); If(isAsphodelNum(num))
System.out.println(num+“是水仙花数”); Else
System.out.println(num+“不是水仙花数”);}} 16.打印以下杨辉三角形(10行) 1 1 1 1 2 1 1 3 3 1
1 4 6 4 1 ...
Public class yanghui
{public static void main(string args[]) {int i,j; int a[][]=new int[11][11]; For(i=1;i<11;i++)
{a[i][i]=1; a[i][1]=1;} For(i=3;i<11;i++) For(j=2;j<i-1;j++)
a[i][j]=a[i-1][j-1]+a[i-1][j]; For(i=1;i<11;i++) {for(j=1;j<=i;j++)
System.out.print(a[i][j]+“ ”); System.out.println(“\n”);} System.out.println(“\n”);}}
1.输出“Hello Java” Public class HelloJava
{Public static void main(string[] args) {system.out.println(“Hello Java”);}}
2.圆球体积为4/3пr3
,求圆球体积 Public class square
{public static void main(string args[]) {double r=0,v=0;
r=Double.parseDouble(args[0]); v=4*3.1415/3*r*r*r;
system.out.println(“体积为:”+v);}} 3.利用if嵌套完成相同的功能 If(grade==6||grade==7) {a=11;b=22;}
Else if(grade==5) {a=33;b=44;} Else {a=55;}
4.将百分制成绩转换为5级制成绩 Public class classificatcion
{public static void main(string args[]) {char level;
Int grade=integer.parseint(args[0]); Int num=grade/10; Switch(num) {case 6:
Level=’D’;break; case 7:
Level=’C’;break; case 8:
Level=’B’;break; case 9:
Level=’A’;break; case 10:
Level=’A’;break; Default:
Level=’E’;} system.out.println
(“该生成绩为:”+level);}} 5.利用for语句,形成如下图形 * ** *** **** *****
Public class format
{Public static void main(string args[]) {int i,j;
For(j=1;j<=i;j++)
System.out.print(“*”); System.out.print(“\n”);}}} 6.利用while,计算2+4+6+...+100 Public class sumofeven
{Public static void main(string args[]) {int i=2,sum=0; While(i<=100) {sun+=i; i+=2;}
System.out.println(“结果为:”+sum);}} 7.利用for,计算1+3+5+...+99 Public class sumofodd
{Public static void main(string args[]) {int i,sum=0;
For(i=1;i<100;i=i+2) {sun+=i;}
System.out.println(“结果为:”+sum);}} 8.利用do...while,计算1!+2!+...+100! Public class factorial
{Public static void main(string args[]) {int i=1;
Double n=1,sum=0; Do
{n=n*i;sum=sum+n;i++;}whlie(i<=100); System.out.println(“结果为:”+sum);}} 9.绳长3000m,每天减去一半,要几天绳子长度会短于5m?
Public class rope
{Public static void main(string args[]) {int daycount=0;
Float rope_length=3000; Do
{rope_length=rope_length/2;daycount++; }while(rope_length>=5); System.out.println
(“需要时间为:”+daycount+“天”);}} 10.求所有水仙花数
Public class Narcissus
{Public static void main(string args[]) {int i,j,k,n; i=j=k=0; For(n=100;n<1000;n++)
{i=n/100; j=n/10-i*10; k=n%10; If(n==i*i*i+j*j*j+k*k*k)
System.out.println(n+“”);}}}
3
11.地球半径6400km,一人9.8s跑了100m,跑地球一圈需要几天
Public class runaroungtheearth
{Public static void main(string args[]) {double s,meterPerDay,daycount=0; Long r=6400000; S=3.1415*2*r;
Meterperday=24*60*60*100/9.8; Daycount=s/meterperday;
System.out.println(“需要天数为:”
+daycount);}} 12.判断素数
Public class prime
{Public static void testprime(int m) {boolean isPrime=ture; For(int i=2;i<m;i++) If(m%i==0)
{isPrime==false; break;} If(isPrime)
System.out.println(“True”); Else
System.out.println(“False”);} Public static void main(string args[]) {if(args.length!=1)
{ System.out.println(“输入格式错误!请按照此格式输入:java Prime m”); System.exit(0);}
Int number=Integer.parseInt(args[0]); testPrime(number);}}
13.计算1-1/2+1/3-1/4+1/5-1/6+...-1/50 Public class series
{Public static double calculateNum() {int sign=-1;
Double under=1.0,sum=1.0,term; For(int i=2;i<=50;i++) {under=i;
Term=sign/under; Sun=sum+term; Sign=-sian; }return sum;
}public static void main(String args[]) {system.out.println
(“结果为:”+calculateNum());}}
4
14.利用阶乘计算1!+2!+...+10! Public class factorial
{public static int factor(int m) {if(m<=1) return 1;
Else return m*factor(m-1);}
Public static void main(string args[]) {long sum=0;
For(int i=1;i<=10;i++)
Sum=sum+factor(i);
System.out.println(“结果为:”+sum);}} 15.判断一个3位数是否为水仙花数 Public class AsphodelNum {public static boolean isAsphodelNum(int m) {int i,j,k; i=m/100; j=m/10%10; k=m%10; If(m==i*i*i+j*j*j+k*k*k)
Return true;
Else return false;}
Public static void main(string args[]) {if(args.length!=1)
{System.out.println(“输入格式错误!请按照此格式输入:java AsphodelNum m”); System.exit(0);}
Int num=Integer.parseInt(args[0]); If(isAsphodelNum(num))
System.out.println(num+“是水仙花数”); Else
System.out.println(num+“不是水仙花数”);}} 16.打印以下杨辉三角形(10行) 1 1 1 1 2 1 1 3 3 1
1 4 6 4 1 ...
Public class yanghui
{public static void main(string args[]) {int i,j; int a[][]=new int[11][11]; For(i=1;i<11;i++)
{a[i][i]=1; a[i][1]=1;} For(i=3;i<11;i++) For(j=2;j<i-1;j++)
a[i][j]=a[i-1][j-1]+a[i-1][j]; For(i=1;i<11;i++) {for(j=1;j<=i;j++)
System.out.print(a[i][j]+“ ”); System.out.println(“\n”);} System.out.println(“\n”);}}
1.输出“Hello Java” Public class HelloJava
{Public static void main(string[] args) {system.out.println(“Hello Java”);}}
2.圆球体积为4/3пr3
,求圆球体积 Public class square
{public static void main(string args[]) {double r=0,v=0;
r=Double.parseDouble(args[0]); v=4*3.1415/3*r*r*r;
system.out.println(“体积为:”+v);}} 3.利用if嵌套完成相同的功能 If(grade==6||grade==7) {a=11;b=22;}
Else if(grade==5) {a=33;b=44;} Else {a=55;}
4.将百分制成绩转换为5级制成绩 Public class classificatcion
{public static void main(string args[]) {char level;
Int grade=integer.parseint(args[0]); Int num=grade/10; Switch(num) {case 6:
Level=’D’;break; case 7:
Level=’C’;break; case 8:
Level=’B’;break; case 9:
Level=’A’;break; case 10:
Level=’A’;break; Default:
Level=’E’;} system.out.println
(“该生成绩为:”+level);}} 5.利用for语句,形成如下图形 * ** *** **** *****
Public class format
{Public static void main(string args[]) {int i,j;
For(j=1;j<=i;j++)
System.out.print(“*”); System.out.print(“\n”);}}} 6.利用while,计算2+4+6+...+100 Public class sumofeven
{Public static void main(string args[]) {int i=2,sum=0; While(i<=100) {sun+=i; i+=2;}
System.out.println(“结果为:”+sum);}} 7.利用for,计算1+3+5+...+99 Public class sumofodd
{Public static void main(string args[]) {int i,sum=0;
For(i=1;i<100;i=i+2) {sun+=i;}
System.out.println(“结果为:”+sum);}} 8.利用do...while,计算1!+2!+...+100! Public class factorial
{Public static void main(string args[]) {int i=1;
Double n=1,sum=0; Do
{n=n*i;sum=sum+n;i++;}whlie(i<=100); System.out.println(“结果为:”+sum);}} 9.绳长3000m,每天减去一半,要几天绳子长度会短于5m?
Public class rope
{Public static void main(string args[]) {int daycount=0;
Float rope_length=3000; Do
{rope_length=rope_length/2;daycount++; }while(rope_length>=5); System.out.println
(“需要时间为:”+daycount+“天”);}} 10.求所有水仙花数
Public class Narcissus
{Public static void main(string args[]) {int i,j,k,n; i=j=k=0; For(n=100;n<1000;n++)
{i=n/100; j=n/10-i*10; k=n%10; If(n==i*i*i+j*j*j+k*k*k)
System.out.println(n+“”);}}}
5
11.地球半径6400km,一人9.8s跑了100m,跑地球一圈需要几天
Public class runaroungtheearth
{Public static void main(string args[]) {double s,meterPerDay,daycount=0; Long r=6400000; S=3.1415*2*r;
Meterperday=24*60*60*100/9.8; Daycount=s/meterperday;
System.out.println(“需要天数为:”
+daycount);}} 12.判断素数
Public class prime
{Public static void testprime(int m) {boolean isPrime=ture; For(int i=2;i<m;i++) If(m%i==0)
{isPrime==false; break;} If(isPrime)
System.out.println(“True”); Else
System.out.println(“False”);} Public static void main(string args[]) {if(args.length!=1)
{ System.out.println(“输入格式错误!请按照此格式输入:java Prime m”); System.exit(0);}
Int number=Integer.parseInt(args[0]); testPrime(number);}}
13.计算1-1/2+1/3-1/4+1/5-1/6+...-1/50 Public class series
{Public static double calculateNum() {int sign=-1;
Double under=1.0,sum=1.0,term; For(int i=2;i<=50;i++) {under=i;
Term=sign/under; Sun=sum+term; Sign=-sian; }return sum;
}public static void main(String args[]) {system.out.println
(“结果为:”+calculateNum());}}
6
14.利用阶乘计算1!+2!+...+10! Public class factorial
{public static int factor(int m) {if(m<=1) return 1;
Else return m*factor(m-1);}
Public static void main(string args[]) {long sum=0;
For(int i=1;i<=10;i++)
Sum=sum+factor(i);
System.out.println(“结果为:”+sum);}} 15.判断一个3位数是否为水仙花数 Public class AsphodelNum {public static boolean isAsphodelNum(int m) {int i,j,k; i=m/100; j=m/10%10; k=m%10; If(m==i*i*i+j*j*j+k*k*k)
Return true;
Else return false;}
Public static void main(string args[]) {if(args.length!=1)
{System.out.println(“输入格式错误!请按照此格式输入:java AsphodelNum m”); System.exit(0);}
Int num=Integer.parseInt(args[0]); If(isAsphodelNum(num))
System.out.println(num+“是水仙花数”); Else
System.out.println(num+“不是水仙花数”);}} 16.打印以下杨辉三角形(10行) 1 1 1 1 2 1 1 3 3 1
1 4 6 4 1 ...
Public class yanghui
{public static void main(string args[]) {int i,j; int a[][]=new int[11][11]; For(i=1;i<11;i++)
{a[i][i]=1; a[i][1]=1;} For(i=3;i<11;i++) For(j=2;j<i-1;j++)
a[i][j]=a[i-1][j-1]+a[i-1][j]; For(i=1;i<11;i++) {for(j=1;j<=i;j++)
System.out.print(a[i][j]+“ ”); System.out.println(“\n”);} System.out.println(“\n”);}}
学习有困难可以加扣:578024144进行交流得到帮助还可以关注微信公众号:javaniuniu获取免费得听课权限