//for语句嵌套
class ForForDemo
{
public static void main(String[] args)
{
for(int x =0;x<3;x++)
{
for(int y=0;y<4;y++)
{
System.out.print("*");
}
System.out.println();//用来换行
}
System.out.println("-----------------");
/*
**
*
*/
for(int x=0;x<5;x++)
{
for(int y=x;y<5;y++)
{
System.out.print("*");
}
System.out.println();
}
System.out.println("---------------------");
/*
*
**
*/
for(int x=1;x<6;x++)
{
for(int y=0;y<x;y++)
{
System.out.print("*");
}
System.out.println();
}
System.out.println("----------------------------");
for(int x=1;x<=9;x++)
{
for(int y=1;y<=x;y++)
{
System.out.print(y+"*"+x+"="+y*x+"\t");
}
System.out.println();
}
}
}
/*
对于打印长方形,外循环控制着行数,内循环控制着每一行的列数,也就是一行中元素的个数。
*/
//等腰三角形图形
/*
—-*
—* *
–* * *
-* * * *
*/
class TuXing
{
public static void main(String[] args)
{
for(int x=0;x<5;x++)
{
for(int y=x+1;y<5;y++)
{
System.out.print(” “);
}
for(int z=0;z<=x;z++)
{
System.out.print(“* “);
}
System.out.println();
}
}
}
break(跳出); continue(继续);
class OtherDemo
{
public static void main(String[] args)
{
//break
w:for(int x=0;x<3;x++)
{
q:for(int y=0;y<4;y++) //标号只能应用于循环中
{
System.out.println(“x=”+x);
break q;
}
}
System.out.println(“——————–”);
//continue:只能作用于循环结构.结束本次循环,继续下次循环。
for(int x=0;x<10;x++)
{
if(x%2==0)
continue;
System.out.println(“x=”+x);
}
//记住break和continue语句的作用范围,break和continue单独存在时,下面的语句执行不到
}
}