University stuff.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SumTall.java 378B

123456789101112131415161718192021
  1. import java.util.Scanner;
  2. class SumTall {
  3. public static void main(String[] args) {
  4. Scanner s = new Scanner(System.in);
  5. int sum = 0;
  6. while (true) {
  7. int num = s.nextInt();
  8. //Exit the loop if the user inputs 0
  9. if (num == 0)
  10. break;
  11. sum += num;
  12. }
  13. //After the user input 0, show them the sum of all their inputs
  14. System.out.println("Sum: "+sum);
  15. }
  16. }