Source of Reverse6.java


  2: import java.util.Scanner;

  4: /**
  5:  * A class to reverse six integer values entered by the user.
  6:  * (It prints them out in the reverse order that the user entered them.)
  7:  * It creates six individual variables to hold the six values.
  8:  *
  9:  * @author Mark Young (A00000000)
 10:  */
 11: public class Reverse6 {
 12:     public static void main(String[] args) {
 13:         // create the variables
 14:         Scanner kbd = new Scanner(System.in);
 15:         int n1, n2, n3, n4, n5, n6;

 17:         // introduce yourself
 18:         System.out.print("\n\n"
 19:                 + "A program to reverse six numbers entered by the user.\n\n");

 21:         // read the numbers
 22:         System.out.println("Enter the six numbers below:\n");
 23:         n1 = kbd.nextInt();
 24:         n2 = kbd.nextInt();
 25:         n3 = kbd.nextInt();
 26:         n4 = kbd.nextInt();
 27:         n5 = kbd.nextInt();
 28:         n6 = kbd.nextInt();
 29:         kbd.nextLine();

 31:         // print them out again, in reverse order
 32:         System.out.println("In reverse order they are:\n"
 33:                 + n6 + ", " + n5 + ", " + n4 + ", "
 34:                 + n3 + ", " + n2 + ", and " + n1);

 36:         // print some blank lines at the end
 37:         System.out.print("\n\n");
 38:     }
 39: }