[英]Histogram is upside down
I want my histogram to show like this 我希望我的直方图显示如下
but I get it upside down like this 但是我把它颠倒过来
This is my code. 这是我的代码。
public void printHistogram() {
System.out.println("Print histogram");
histogram = new boolean[4][6];
int[] lengthTemp = numberEach(numbers);
for (int u = 0; u < 4; u++) {
for (int m = 0; m < 6; m++) {
if (lengthTemp[m] >= 1) {
histogram[u][m] = true;
lengthTempk[m] -= 1;
}
}
}
for (int s1 = 0; s1 < 4; s1++) {
for (int s2 = 0; s2 < 6; s2++) {
if (histogram[s1][s2]) {
System.out.print("*\t");
} else {
System.out.print(" \t");
}
}
System.out.println("");
}
}
I keep trying to reverse it but I never get it right. 我一直试图扭转它,但我从来没有做对。 I found out that you just need to reverse it to the middle but I can't figure it out. 我发现你只需将它反转到中间但我无法弄明白。
Every true in the array histogram represents a star. 数组直方图中的每个真值都代表一个星。
In the first dimension of your array histogram
, the first index 0
is printed first, at the top of the histogram, not the bottom. 在数组histogram
的第一维中,首先打印第一个索引0
,位于直方图的顶部,而不是底部。
To get your print outs to print correctly, print from the end of the first dimension s1
, not the beginning. 要使打印输出正确打印,请从第一个尺寸s1
的末尾打印,而不是从头开始打印。 Subtract s1
from the length of the 2D array. 从2D数组的长度中减去s1
。 Change your s1
for loop to iterate backwards. 将s1
for循环更改为向后迭代。
for (int s1 = 0; s1 < 4; s1++) {
to 至
for (int s1 = 3; s1 >= 0; s1--) {
reverse the reading of the array : 反转数组的读数:
for (int s1 = 3; s1 >= 0; s1--) {
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.