Спасибо, что посмотрели мой код. Я изучаю Java и сталкиваюсь с проблемой, которая сводит меня с ума.Как добавить внутри цикла while в java?
/*
* The loop reads positive integers from standard input and that
* terminates when it reads an integer that is not positive. After the loop
* terminates, it prints out, separated by a space and on a single line, the
* sum of all the even integers read and the sum of all the odd integers
*/
Дело в том, что переменные не добавляются! Я знаю, что мой синтаксис хорош. Я думаю, что есть что-то о языке Java, который я не понимаю, с тем, как цикл работает и добавляет.
import java.util.Scanner;
class Testing2 {
public static void main(String[] args) {
int sumP = 0;
int sumO = 0;
Scanner stdin = new Scanner(System.in);
System.out.println("Enter a positive or negative integer: ");
while ((stdin.nextInt()) >= 0) {
if (stdin.nextInt() % 2 == 0)
sumP += stdin.nextInt();
else
sumO += stdin.nextInt();
}
System.out.println(sumP + " " + sumO);
stdin.close();
}
};
Уверены ли вы? Почему бы не добавить несколько операторов System.out.println() для отслеживания выполнения? – kosa