Source of SumNumbers.java


  1: import java.util.Scanner;

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

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

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

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

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

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

 29: }