Hello,
i tried this and the program actually works and imo fullfils all the conditions. -1 is included in the sum and the sum is printed.
Also i tried to print the sum after every input, but it also didn't work.
Whats wrong here?
Thanks already
package de.codegym.task.task04.task0442;
/*
Addieren
*/
import java.io.*;
import java.util.Scanner;
public class Solution {
static Scanner input = new Scanner(System.in);
public static void add(){
int sum = 0;
while (true){
int number = input.nextInt();
sum = sum + number;
if (number == -1){
System.out.println(sum);
break; }
}
}
public static void main(String[] args) throws Exception {
add();
}
}