/*
for循环嵌套的应用
*/
class ForForTest2
{
public static void main(String[] args)
{
/*
控制台输出以下形状
*****
****
***
**
*
*/
/*
for(int x=0; x<5; x++)
{
for(int y=0; y<5; y++)
{
System.out.print("*");
}
System.out.println();
}
*/
/*
继续思考
列是变化的
0 5
1 5
2 5
3 5
4 5
*/
/*
int z = 0;
for(int x=0; x<5; x++)
{
for(int y=z; y<5; y++)
{
System.out.print("*");
}
System.out.println();
z++;
}
*/
/*
发现z的变化和x的变化是一致的。所以不需要定义z变量了。直接使用x。
*/
for(int x=0; x<5; x++)
{
for(int y=x; y<5; y++)
{
System.out.print("*");
}
System.out.println();
}
System.out.println("--------------------");
/*
控制台输出以下形状
*
**
***
****
*****
*/
//思考 0 1/2/3/4/5
for(int x=0; x<5; x++)
{
for(int y=0; y<=x; y++)
{
System.out.print("*");
}
System.out.println();
}
/*
总结:
尖尖朝上的形状,循环条件表达式变化。
尖尖朝下的形状,初始化表达式变化。
*/
System.out.println("--------------------");
/*
打印3以内的99乘法表
1*1=1
2*1=2 2*2=4
3*1=3 3*2=6 3*3=9
*/
for(int x=1; x<=3; x++)
{
for(int y=1; y<=x; y++)
{
System.out.print(x+"*"+y+"="+x*y+" ");
}
System.out.println();
}
System.out.println("--------------------");
//打印99乘法表
for(int x=1; x<=9; x++)
{
for(int y=1; y<=x; y++)
{
System.out.print(x+"*"+y+"="+x*y+"\t");
}
System.out.println();
}
//\称为转义控制字符,跟在其后的字符意义已经发生了改变
/*
System.out.println('\'');//输出'
System.out.println('\n');//输出换行
System.out.println('\t');//输出制表符 tab
*/
System.out.println("--------------------");
/*
请在控制台输出
* * * * *
-* * * *
--* * *
---* *
----*
*/
for(int x=0; x<5; x++)
{
for(int y=0; y<x; y++)
{
//System.out.print("-");
System.out.print(" ");
}
for(int y=x; y<5; y++)
{
System.out.print("* ");
}
System.out.println();
}
/*
把上面的图形到这打 练习
*/
for (int x=1;x<=9 ;x++ )
{
for (int y=x;y<9 ;y++ )
{
System.out.print("=");
}
for (int c=1;c<=x ;c++ )
{
System.out.print("* ");
}
System.out.println();
}
}
}