统计信息

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

P5Q6

2008-04-08 14:15:12

天气: 晴朗 心情: 高兴

/*fileName:P5Q06.java
*Name:Wang Chaoran
* Description:
6 (Displaying patterns)
Write a method to display a pattern as follows:
 
              1
            2 1
          3 2 1
  ...
n n-1 ... 3 2 1
refer to P4Q3;P4Q2;
The method header is
public static void displayPattern(int n)
*/
import java.util.Scanner;
public class P5Q06{
  public static void main(String[] args){
    //Input
    Scanner scan = new Scanner(System.in);
    System.out.println("Please input an integer");
    int n = scan.nextInt();
    //Output
    displayPattern(n);
  }
  public static void displayPattern(int n){
    String a = " ";
    for(int i=1;i<=n;i++){
       //print blank
      for(int k=n;k>i;k--){
      int p=k;
      while(p != 0){
          p /= 10;
         System.out.print(a);
      }
         System.out.print(a);
                 
      } 
       //print number
      for(int j=i;j>=1;j--)
       System.out.print(j+" ");
        //print next line
      System.out.println();
   
  }
}
}

//printf("%2s"," ");printf("%2d"," ");
   


加入收藏 编辑 审核

TAG: computing

我来说两句

OPEN

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