统计信息

  • 访问数:10944
  • 博客数:142
  • 建立时间:2008-01-05
  • 更新时间:2008-05-21
我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!

P4Q2

2008-02-13 16:22:14

天气: 晴朗 心情: 高兴

/*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+" ");
      }
    }
  }
}
     


加入收藏 编辑 审核

TAG: computing

我来说两句

OPEN

Powered by X-Space 1.2 © 2001-2006 Comsenz Technology Ltd