所以我无法垂直打印我的代码,无论我做什么,它都会继续水平打印。第一个图像是我的输出看起来如何,第二个图像是它应该是什么。
// pixel counter
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {
pixelcounter [s.nextInt()/ binwidth] += 1;
}
}
// histogram
for (int q = 0; q < pixelcounter.length; q++) {
if (binmin < 10) {
System.out.print(" " + binmin + ":");
} else {
System.out.print(binmin + ":");
}
int num_stars = (int) ((((double) pixelcounter[q] * 100.0/ area)) + 0.5)
for (i = 0; i < num_stars; i++) {
System.out.print("*");
}
System.out.println();
binmin += binwidth;
}
答案 0 :(得分:2)
您应该使用:
System.out.println(" " + binmin + ":");
如果您使用System.out.print(" " + binmin + ":");
,则会在同一行中打印所有内容。
将其更改为println将确保您的输出打印在不同的行上。
答案 1 :(得分:0)
没有垂直打印的东西。你可能想要做的是创建空矩阵/ 2D数组并用你的数据填充它(从左边开始)。对于常量长度或行,您可以在没有数据和空格的地方插入astrix(*)。然后你转置矩阵并逐行打印。