if(max.hasNextInt())
{
num = max.nextInt();
}
如何在使用掃描儀和標記值時找到最大數量?我的方法只顯示輸入的最後一個整數。 我已經在這個幾個小時,並已經把我的自豪感睡覺,我需要幫助....請幫助..........查找JAVA中的最大數字
if(max.hasNextInt())
{
num = max.nextInt();
}
如何在使用掃描儀和標記值時找到最大數量?我的方法只顯示輸入的最後一個整數。 我已經在這個幾個小時,並已經把我的自豪感睡覺,我需要幫助....請幫助..........查找JAVA中的最大數字
你條件,測試,如果當前數字更高比當前的最大值是錯誤的地方。
變化
if(max.hasNextInt())
{
num = max.nextInt();
}
else
{
if(num > totmax)
{
totmax = num;
}
...
到
if(max.hasNextInt())
{
num = max.nextInt();
if(num > totmax)
{
totmax = num;
}
}
else
{
...
謝謝,我終於可以休息大聲笑 – user3185727
您也可以考慮使用[Math.max](http://docs.oracle.com/javase/7/docs/api/java/lang/Math.html#min(int,%20int))來獲得最大值。 –
@ user3185727您應該在回答後不會編輯細節。 – Amila