1
我試圖用1個輸入來獲得發生最大數量的計數。獲取發生次數的最大值
我的代碼如下所示: -
Scanner input = new Scanner(System.in);
int num = input.nextInt();
int max = 0, count = 0, value, lastValue = 0;
while (num > 0){
value = num % 10;
num = num/10;
if (value > lastValue){
max = value;
}
lastValue = value;
}
System.out.println(max);
System.out.println("count is " + count);
}
我怎麼能計算出最大號的數量?
假設我有類似於2556621
的輸入count
應該是2
。
在什麼時候是你卡住? – pedromss
@pedromss自從我使用1個輸入項後,獲得最大數量的計數,使用多個輸入項很容易,但在我的情況下,我可以如何實現這一點。 ? – user1058652
爲什麼你使用一個輸入呢? –