publicclassHomework2{publicstaticvoidmain(String[] args){double a =200;int b =0;while(a<=1000){
a=a*1.25;
b=b+1;}System.out.print("第"+b+"年学校人数超过1000");}}
结果
3、求两个数最大公约数
importjava.util.Scanner;publicclassHomework3{publicstaticvoidmain(String[] args){Scanner sc=newScanner(System.in);System.out.print("请输入一个数:");int a = sc.nextInt();System.out.print("请输入一个数:");int b = sc.nextInt();if(a<b){for(int i=a;i>=1;i--){if(a%i==0&&b%i==0){System.out.print(i);break;}}}else{for(int u=b;u>=1;u--){if(a%u==0&&b%u==0){System.out.print(u);break;}}}}}