0
i am trying to make a program which display the sum of numbers only if user write a positive number using only while loop
the program take any number of numbers from the user and store the sum of them and display the sum only if the user enter a negative number in my case the output is the sum but added to the negative number https://onlinegdb.com/G6FMvUN70
2 ответов
+ 1
int sum = 0;
Scanner sc = new Scanner(System.in);
input = sc.nextInt();
while (input>=0) {
sum += input;
input = sc.nextInt();
}
System.out.println(sum);
+ 1
i found the bug
and here's the right code
https://onlinegdb.com/PqU6Vu4Zb