// Whitaker Brand // CSE142 // Instructor: Whitaker Brand // TA: Whitaker Brand // // This class demonstrates some basics about variables. public class VariableExample { public static void main(String[] args) { // basic int (integer) and double (real) number int x = 3; double grade = 4.0; // You can hold strings in variables, too! String s = "hello"; System.out.println(x); // prints 3 // We can change what we stored in x: x = 7; System.out.println(x); // prints 7 // This line of code adds 6 to x, but doesn't do anything with // the result of the multiplication. It's an illegal statement, // and doesn't make much sense in java. // x + 6; // This is the correct way to add 6 to x: reassign it. x = x + 6; System.out.println(x); // prints 13 // x++ is shorthand for x = x + 1 -- they do the same thing x = x + 1; x++; // Note the + with the String: it puts the numerical value // of x onto the end of the String. System.out.println("the value of x is " + x); // prints: the value of x is 15 } }