算法第四版1.1.11
就这样
package com.zzh; import edu.princeton.cs.algs4.StdOut; import edu.princeton.cs.algs4.StdRandom; public class Test { public static void main(String[] args) { // TODO Auto-generated method stub boolean[][] a= new boolean[6][2]; randomRank(a); initial(a); } public static boolean[][] randomRank(boolean[][] a) { for(int i=0;i<a.length;i++) { for(int j=0;j<a[i].length;j++) { if (StdRandom.bernoulli(0.5)) a[i][j]=true; else a[i][j]=false; } } return a; } public static void initial(boolean[][] a) { for(int i=0;i<a.length;i++) { for(int j=0;j<a[i].length;j++) { StdOut.print("第"+i+"行第"+j+"列的元素为:"); StdOut.println(a[i][j]==true?"*":" "); } } } }
勿在浮沙筑高台