// Miya Natsuhara // 06-28-2019 // CSE142 // TA: Grace Hopper // A few examples of using and working with variables. public class VariablePractice { public static void main(String[] args) { // variables // declaration int x; // initialization (first time you assign to a variable) x = 5; // reassignment x = -2; // decl & init in one lines int y = 25; // can assign variables to results of expressions y = 80 - 6 * 4 % 12; x = y + 20; // even expressions involving other variables! y = 0; x += 1; // equivalent to x = x + 1 x -= 5; // equivalent to x = x - 5 /* x += 1 same as x = x + 1 same as x++ (incrementing x by 1) x -= 1 same as x = x - 1 same as x-- (decrementing x by 1) */ // To print out the value in a variable, use the variable's name in the () of // System.out.println System.out.println("x = " + x); System.out.println("y = " + y); } }