Source of Sum3A_Interactive.java


  1: // Sum3A_Interactive.java
  2: //  read and sum three numbers from the user

  4: import java.util.Scanner;

  6: /**
  7:  * Reads and sums three numbers entered by the user.
  8:  *
  9:  * @author Mark Young (A00000000)
 10:  */
 11: public class Sum3A_Interactive {

 13:     public static void main(String[] args) {
 14:         // create variables
 15:         Scanner kbd = new Scanner(System.in);
 16:         int n1, n2, n3;

 18:         // read numbers
 19:         System.out.println("\n\nEnter three numbers below: ");
 20:         n1 = kbd.nextInt();
 21:         n2 = kbd.nextInt();
 22:         n3 = kbd.nextInt();
 23:         kbd.nextLine();

 25:         // print their sum, echoing input
 26:         System.out.println("\nThe sum of " + n1 + ", " + n2 + ", and " + n3
 27:             + " is " + (n1 + n2 +n3) + ".\n");
 28:     }

 30: }