统计信息

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

P5Q14

2008-04-09 09:45:23

天气: 晴朗 心情: 高兴

/*fileName:P5Q14.java
*Name:Wang Chaoran
* Description:
14 (Displaying matrix of 0s and 1s)
Write a method that displays an n by n matrix using the following header:
public static void printMatrix(int n)
Each element is 0 or 1, which is generated randomly. Write a test program
that prints a 3 by 3 matrix that may look like this:
0 1 0
0 0 0
1 1 1
*/
public class P5Q14{
  public static void main(String[] args){
    printMatrix(3);
  }
  public static void printMatrix(int n){
    for(int i=1;i<=n;i++){
      for(int j=1;j<=n;j++)
       System.out.printf("%-2.0f",Math.floor(Math.random()*2));
     System.out.println();
    }
  }
}
加入收藏 编辑 审核

TAG: computing

我来说两句

OPEN

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