2016-09-14 99 views
0

所以我无法垂直打印我的代码,无论我做什么,它都会继续水平打印。第一张图片是我的输出结果,第二张图片是它的样子。如何让代码垂直打印

// 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; 
} 

this is what the output currently looks like

this is what the output is supposed to look like

+1

我应该认为这与JavaScript无关吗? – vlaz

+0

此外,你正在使用'.print',你想'.println' – vlaz

回答

2

你应该使用:

System.out.println(" " + binmin + ":"); 

如果使用System.out.print(" " + binmin + ":");将打印在同一行的一切。

将其更改为println将确保您的输出打印在单独的行中。

+0

,而这确实有效,这不完全是我想如何垂直打印 – Alexis

0

没有垂直打印的东西。你可能想要做的是创建空矩阵/二维数组,并用数据填充(从左边)。对于恒定的长度或行,你插入astrix(*)你有数据和空间的地方“”,而你没有。然后你转换矩阵并逐行打印。