DoWhile循环
{
public static void main(String[] args) {
int i = 0;
int sum = 0;
do {
sum = sum + i;
i++;
} while (i <= 100);
System.out.println(sum);
}
}
{
int a = 0;
while (a<0){
System.out.println(a);
a++;
}
System.out.println("=======================");
do {
System.out.println(a);
a++;
}while (a<0);
}
}
九九乘法表
{
for (int j = 1; j <=9; j++) {
for (int i = 1; i <=j; i++) {
System.out.print(j+"*"+i+"="+ (j*i) +"\t");
}
System.out.println();
}
}
}
for循环中的死循环
for(;;){
内容
}
foe案例
package com.lol.LiOu.base;
public class ForDemo03 {
public static void main(String[] args) {
for (int i = 0; i <= 1000; i++) {
if (i%5==0){
System.out.print(i+"\t");
}
if (i%(5*3)==0){ //每行
System.out.println();
//System.out.print("\n");
}
}
}
}
三角形
{
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 j = 1; j < i; j++) {
System.out.print("*");
}
System.out.println();
}
}
}