Source of Variables.java


  1: /**
  2:  * Create and manipulate some variables.
  3:  *
  4:  * @author Mark Young (A00000000)
  5:  */
  6: public class Variables {

  8:     /**
  9:      * Run this program.
 10:      *
 11:      * @param args command lines arguments (ignored)
 12:      */
 13:     public static void main(String[] args) {
 14:         // create variables with values
 15:         int n = 10;
 16:         double x = 4.50833;
 17:         String s = "Hello";
 18:         char capitalA = 'A';
 19:         boolean isSo = true;

 21:         // report some values
 22:         System.out.println("\n\tint n = 10;\n"
 23:                          + "\tdouble x = 4.50833;\n"
 24:                          + "\tString s = \"Hello\";");
 25:         System.out.println("n is " + n + ", x is " + x + ", and s is " + s);

 27:         // change some values
 28:         n = 20;
 29:         x = 34.001;
 30:         s = "Bye!";

 32:         // report some values
 33:         System.out.println("\n\tn = 20;\n"
 34:                          + "\tx = 34.001;\n"
 35:                          + "\ts = \"Bye!\";");
 36:         System.out.println("n is " + n + ", x is " + x + ", and s is " + s);

 38:         // modify some values
 39:         n += 5;
 40:         x -= 0.001;
 41:         s += " Bye!";

 43:         // report some values
 44:         System.out.println("\n\tn += 5;\n"
 45:                          + "\tx -= 0.001;\n"
 46:                          + "\ts += \" Bye!\";");
 47:         System.out.println("n is " + n + ", x is " + x + ", and s is " + s);
 48:     }

 50: }