println和prlint的区别就是前者不能换行操作,后者可以
while循环

package choose;public class Demo02 {public static void main(String[] args) {//计算1+2+3+...+100int a = 0;int sum = 0;while (a<=100){sum += a;a++;}System.out.println(sum);}}
do…while循环
for循环
第二个题目代码
package choose;public class Demo03 {public static void main(String[] args) {//for循环输出1~1000之间可以被5整除的数,并且每行输出三个数for (int i = 0; i <= 1000; i++) {if(i%5==0){System.out.println(i+"\t");}if (i%(3*5)==0){System.out.println("\n");}}}}
第三个题目代码
package choose;public class Demo04 {public static void main(String[] args) {for (int i = 1; i <= 9; i++) {for (int i1 = 1; i1 <= i; i1++) {System.out.print(i1+"*"+i+"="+(i*i1)+"\t");}System.out.print("\n");}}}
1*1=11*2=2 2*2=41*3=3 2*3=6 3*3=91*4=4 2*4=8 3*4=12 4*4=161*5=5 2*5=10 3*5=15 4*5=20 5*5=251*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=361*7=7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=491*8=8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=641*9=9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=81进程已结束,退出代码为 0
Java5中引入了一种主要用于数组的增强型for循环

package choose;public class Demo05 {public static void main(String[] args) {int[] numbers = {10,20,30,40,50};//定义一个数组//增强for循环for(int x:numbers){System.out.println(x);/**上方等价于下面语句* for(int i = 0;i < 5;i++)* Systen.out.println(numbers[i])*/}}}
1020304050进程已结束,退出代码为 0
打印一个三角形
package choose;public class Demo06 {public static void main(String[] args) {//打印三角形for (int i = 1; i <= 5; i++) {for (int j = 5;j >= i;j--){System.out.print(" ");}for(int j = 1;j <= i;j++){System.out.print("*");}for(int x = 1;x < i;x++){System.out.print("*");}System.out.print("\n");}}}
输出结果
*************************进程已结束,退出代码为 0
