无聊测试下随机数,但println和print都不行,要么一行要么一列看起来麻烦。
是随机数并且我for循环100遍看随机出哪些数,所以就用if判断配合%取余来判断。
通过自己的胡乱瞎折腾吧,反正无聊撒,现在搞清楚了,想每行打印几个就打印几个并且非常非常简单
关键点如下:
if(i%10==9) {
System.err.println("");
}else {
System.err.print("");
}
前提条件我上面已经说了,for循环了100次。
我自己理出来的公式为:
if(输出的总次数%每行输出个数==每行输出个数-1) {
System.err.println("");
}else {
System.err.print("");
}
上面看懂下面就不需要再继续看了
每行输出10个代码如下:
for(int i = 0 ; i <100; i++) {
int a = (int) (Math.random()*100);
int[] arr = new int[a];
System.err.print(arr.length + "\t");
if(i%10==9) {
System.err.println("");
}else {
System.out.print("");
}
}
Console结果如下:
87 4 64 72 96 15 76 21 12 99
91 69 91 24 86 12 31 68 19 68
46 50 92 86 90 11 50 78 91 80
44 74 96 58 56 35 28 62 11 14
68 91 25 1 0 78 30 51 61 18
83 23 5 89 32 79 21 95 11 62
31 88 83 52 33 75 93 54 88 21
81 41 95 24 49 81 54 53 70 12
9 8 45 46 97 82 91 53 79 75
77 71 5 49 73 65 66 75 83 85
每行输出9个
for(int i = 0 ; i <100; i++) {
int a = (int) (Math.random()*100);
int[] arr = new int[a];
System.err.print(arr.length + "\t");
if(i%9==8) {
System.err.println("");
}else {
System.err.print("");
}
}
Console结果:
82 6 64 38 23 42 42 68 48
60 4 95 97 39 22 84 16 27
91 3 33 81 8 98 41 99 8
99 92 83 31 10 17 29 45 9
7 87 16 97 23 48 53 15 81
30 30 78 42 2 48 22 3 39
63 71 78 50 83 98 22 14 97
34 66 71 90 21 83 62 64 16
50 78 74 56 7 90 82 81 60
41 90 42 66 65 42 81 20 52
59 70 5 7 67 72 70 1 91
80
每行13个
for(int i = 0 ; i <100; i++) {
int a = (int) (Math.random()*100);
int[] arr = new int[a];
System.err.print(arr.length + "\t");
if(i%13==12) {
System.err.println("");
}else {
System.err.print("");
}
}
Console结果
17 68 43 9 47 31 75 81 2 52 64 24 84
69 97 8 17 97 77 23 41 18 77 42 70 27
64 78 42 19 24 65 47 95 63 84 77 15 51
58 5 59 8 74 28 61 26 11 50 9 85 8
91 60 48 98 48 81 40 75 90 3 19 6 27
75 70 83 9 11 19 56 49 54 69 31 84 15
23 82 72 14 23 88 47 14 0 41 36 30 63
13 95 0 90 71 34 28 35 3