這裏是我到目前爲止的代碼片段。我的問題是最小值出現爲Integer.MAX_VALUE,而不是我想要的值。 iSpeedMph和壓力都是一維整數數組。Java最小取景器不起作用
//calculating mins
Integer min = Integer.MAX_VALUE;
int minSpeed = Integer.MAX_VALUE;
int minPressure = Integer.MAX_VALUE;
for(i = 0; i < iSpeedMph.length; i++)
{
if (min > iSpeedMph[i])
{
min = iSpeedMph[i];
minSpeed = iSpeedMph[i];
}
}
min = Integer.MAX_VALUE;
for(i = 0; i < pressure.length; i++)
{
if (min > pressure[i])
{
min = pressure[i];
minPressure = pressure[i];
}
}
...
System.out.printf("%7s%2s%-9s%4s%8s%5s%13.3s%5s%16.2s\n", "Minimum", " ", " ", " ", " ", " ", minPressure, " ", minSpeed);
當我打印出最後一行,則終端顯示速度,214爲壓力和21,未經格式化,意味着它們都Integer.MAX_VALUE的。
像這樣的簡單錯誤是最令人討厭的! – DonyorM