Source of SumNumbers.java


  1: package exceptions;

  3: import java.util.Scanner;

  5: /**
  6:  * A class to sum up numbers provided by the user.
  7:  *
  8:  * @author Mark Young (A00000000)
  9:  */
 10: public class SumNumbers {

 12:     public static final Scanner KBD = new Scanner(System.in);

 14:     public static void main(String[] args) {
 15:         int num, sum;

 17:         // introduce yourself
 18:         System.out.println("Enter some positive integers below "
 19:                 + "and I'll tell you their sum.");

 21:         // add up the user input
 22:         sum = 0;
 23:         while ((num = KBD.nextInt()) >= 0) {
 24:             sum += num;
 25:         }

 27:         // report result
 28:         System.out.println("Their sum is " + sum + ".");
 29:     }

 31: }