黑马程序员技术交流社区
标题:
JAVA基础 求解
[打印本页]
作者:
K_LONG
时间:
2015-9-18 21:25
标题:
JAVA基础 求解
关于for嵌套的应用----星型等腰三角形
谢谢
作者:
史世锋
时间:
2015-9-18 21:26
class Fortest2
{
public static void main(String[] args)
{
/*
打印图案:
*****
****
***
**
*
*/
for(int x=5;x>0;x--)
{
for(int y=1;y<=x;y++)
{
System.out.print("*");
}
System.out.print('\n');
}
System.out.println("-------------------");
/*
打印图案:
*
**
***
****
*****
*/
for(int x=1;x<=5;x++)
{
for(int y=1;y<=x;y++)
{
System.out.print("*");
}
System.out.print('\n');
}
System.out.println("-------------------");
/*
打印:
1
12
123
1234
12345
*/
for(int x=1;x<=5;x++)
{
for(int y=1;y<=x;y++)
{
System.out.print(y);
}
System.out.println();
}
System.out.println("-------------------");
/*
打印:
1*1=1
1*2=2 2*2=4
1*3=3 2*3=6 3*3=9
*/
for(int x=1;x<=9;x++)
{
for(int y=1;y<=x;y++)
{
System.out.print(y+"*"+x+"="+(x*y)+"\t");
}
System.out.println();
}
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2