1、循环结构
java循环结构如下:
- 类型一,while
while(1){
System.out.println();
}
- 类型二,do while
与类型一的区别,先执行一次再判断while的条件。
do{
}
while(1);
- 类型三,for
for(int i=0;i<=n;i++){}
2、循环例子
例子1:打印九九乘法表
for(int i =0;i<10;i++){
for(int j=i;j<=i;j++){
System.out.print(j+"*"+i+"="+i*j+"\t");
}
System.out.println();
}
例子2:斐波那契数列1、1、2、3、5、8…
//假设输出100个数
int count=100;
int x=1,y=1,z=0;
for(int i=0;i<=count;i++){
z=x+y;
x=y;
y=z;
System.out.print(z+"\t");
}