小峰视频十:循环while、for
public class demo013 { public static void main(String[] args) { // while 循环语句 int i=1; while (i<=10) { System.out.println(i+" "); i++; } System.out.println("==============="); //do...while循环语句 int j=1; do { System.out.println(j+" "); j++; } while (j<=10); System.out.println("==============="); //for 循环 for(int k=1;k<=10;k++) { System.out.println(k+" "); } //for循环的嵌套 for(int m=0;m<10;m++) { for(int n=0;n<10;n++) { System.out.print("m="+m+",n="+n+" "); } System.out.println(); } //打印所有的水仙花数(一个三位数,各位数的立方和等于改本身) for(int s=100;s<=999;s++) { int x=s/100; int y=(s-x*100)/10; int z=s-x*100-y*10; if(s == x*x*x+y*y*y+z*z*z) { System.out.println(s+" "); } } //打印九九乘法表 for(int a=1;a<10;a++) { for(int b=1;b<=a;b++) { System.out.print(b+"x"+a+"="+a*b+" "); } System.out.println(); } } }
Hello,Java!