1.
package aa; public class text { public static void main(String[] args) { int sum=0; for(int i=1;i<=100;i++){ if(i%3==0){ sum+=i; } } System.out.println("100以内能被3整除的整数和为"+sum); } } package aa; public class text { public static void main(String[] args) { int sum=0,i=1; do{ if(i%3==0){ sum+=i; } i++; }while(i<=100); System.out.println("100以内能被3整除的整数和为"+sum); } } package aa; public class text { public static void main(String[] args) { int sum=0,i=1; while(i<=100){ if(i%3==0){ sum+=i; } i++; } System.out.println("100以内能被3整除的整数和为"+sum); } }
package aa; public class text { public static void main(String[] args) { for(int i=1;i<=9;i++){ if(i==5){ continue; } System.out.println(i); } } }
package aa; import java.util.Scanner; public class text { public static void main(String[] args) { int jc=1; System.out.println("请输入n的值:"); Scanner input=new Scanner(System.in); int n=input.nextInt(); for(int i=1;i<=n;i++){ jc*=i; } System.out.println("n的阶乘是"+jc); } }
package aa; import java.util.Scanner; public class text { public static void main(String[] args) { int i=1; while(i!=6){ System.out.println("请输入学生成绩:"); Scanner input=new Scanner(System.in); int n=input.nextInt(); if(n<0||n>100){ System.out.println("输入的成绩不合法,请重新输入"); i=5; continue; }else{ System.out.println("成绩合法,程序结束"); i=6; } } } }
package aa; import java.util.Scanner; public class text { public static void main(String[] args) { double a=0,x=30000,b=0; for(int i=1;i<=10;i++){ a=x*1.06; b+=a; x=a; } System.out.println("十年后的年薪是"+a+","+"总收入是"+(b+30000)); } }