ユーザーが複数の値を入力し、入力を中止する場合は-1を入力するループを作成します。私はそれがセンチネルを使用する必要があることを知っているが、私はどのようにわからない。Java whileループの中に値を追加して、センチネルを使用して停止します
Scanner myInput = new Scanner(System.in);
int total = 0;
int count = 0;
while(values >= 0)
{
int values;
total += values;
count ++;
System.out.println("Please input your value, type - 1 to stop entering values.");
values = myInput.nextInt();
}
System.out.println ("The sum of all your values is " + total);