2
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("Enter number (0 to quit): ");
//largest to-do
double largest = scan.nextDouble();
double count = 0;
while (largest != 0) {
double input = scan.nextDouble();
//max
if (input > largest) {
// not zero
// while (input > largest){
//
// }
largest = input;
//counter
count = 0;
}
//counter start
if(input==largest){
count++;
}
if (input == 0) {
System.out.println("Largest #: " + largest);
System.out.println("Occurance: " + count);
}
}
}
}
このプログラムは動作します!しかし、その私がその完全なとは思いません... のようなユーザは、それが出力入力を特定の番号を読み取らないようにする方法
-17 -5 -2 -1 -1 -1 0
を入力しようとした場合:
Max: 0
Occurrence: 1
けれども:
:私の心に私はそれになりたいですMax: -1
Occurrence: 3
配列を使用せずにどうすればいいですか?私はカウンターの上から始めたコードの部分を知っています。
ありがとうございます。
0は停止点を意味しますか?文字やその他の文字を停止点にしてみませんか? – dimwittedanimal
0を読んで処理しているので、ゼロを入力したままにしておきたい場合は、「入力!= 0 &&入力>最大」とコメントしたように、「入力>最大」でさらにチェックする必要があります。 – Al1
@dimwittedanimal私はそれをやろうとする可能性がありますが、このプロセスで数字を省略する方法を見てみたかったのですが、 – hellothere