while循环
do...while循环(至少会执行一遍)
For循环(最有效,最灵活)
package scanner; public class ForDemo01 { public static void main(String[] args) { int a = 1;//初始化条件 while(a<=100){//条件判断 System.out.println(a);//循环体 a+=2;//迭代 } System.out.println("while循环结束"); //初始化//判断//迭代 for(int i=1;i<=100;i++){ //100.for System.out.println(i); } System.out.println("for循环结束"); } }
//乘法表 //1.打印第一列 //2.把固定的1用一个循环包起来 //3.去掉重复项,j<=i //4.调整样式
package scanner; public class ForDemo04 { public static void main(String[] args) { for (int i = 1; i <= 9; i++) { for (int j = 1; j <= i; j++) { System.out.print(i+"*"+j+"="+i*j+"\t"); } System.out.println(); } } }
增强型for循环