我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!
天气: 晴朗
心情: 高兴
/*P4Q2
Name:Wang Chaoran
Description:
2 (Printing four patterns using loops)
Use nested loops that print the following patterns in four separate programs:
Pattern I Pattern II Pattern III Pattern IV
1 1 2 3 4 5 6 1 1 2 3 4 5 6
1 2 1 2 3 4 5 2 1 1 2 3 4 5
1 2 3 1 2 3 4 3 2 1 1 2 3 4
1 2 3 4 1 2 3 4 3 2 1 1 2 3
1 2 3 4 5 1 2 5 4 3 2 1 1 2
1 2 3 4 5 6 1 6 5 4 3 2 1 1
*/
class P4Q2
{
public static void main(String[]args)
{
System.out.printf("%-14s%-14s%-14s%-14s","Pattern I","Pattern II","Pattern III","Pattern IV");
for (int i=1;i<=6;i++)
{
System.out.println();
//Pattern I
for(int a=1;a<=i;a++)
{
System.out.print(a+" ");
}
for(int a1=6;a1>=i;a1--)
{
System.out.print(" ");
}
//Pattern II
for(int b=6;b>=i;b--)
{
System.out.print(7-b+" ");
}
for(int b1=1;b1<=6;b1++)
{
System.out.print(" ");
}
//Pattern III
for(int c=i;c>=1;c--)
{
System.out.print(c+" ");
}
//Pattern IV
for(int b1=1;b1<=i;b1++)
{
System.out.print(" ");
}
for(int b=6;b>=i;b--)
{
System.out.print(7-b+" ");
}
}
}
}
导入论坛查看(42)回复(0)引用(0)好评(0) 差评(0)
加入收藏
编辑
审核
TAG:
computing