我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!
天气: 晴朗
心情: 高兴
/*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();
}
}
}
导入论坛查看(61)回复(0)引用(0)好评(0) 差评(0)
加入收藏
编辑
审核
TAG:
computing