/* Experiment.java -- let's take a look at expressions in Java. */ public class Experiment { public static void main(String [] args) { // Practice with arithmetical expressions System.out.println("3 + 4 * 2 = " + (3 + 4 * 2)); System.out.println("35 % 4 = " + (35 % 4)); System.out.println("3*2 > 2*5 returns " + (3*2 > 2*5)); System.out.println("true || false returns " + (true || false)); // Practice the order of operations System.out.println("ugly expression = " + (6 % 7 - (4 - 9) / 2) + 1 / 2 * (3 - 4) * 5 ); // UNCOMMENT THE REST OF THE CODE IN STAGES WHEN YOU ARE READY // TO CONTINUE // Test the associativity of - and / // System.out.println("10 - 3 - 3 = " + (10 - 3 - 3)); // System.out.println("48 / 6 / 3 = " + (48 / 6 / 3)); // Test the associativity of = // int a = 1; // int b = 2; // int c = 3; // System.out.println("a = b = c returns " + (a = b = c)); // System.out.println("And now a = " + a + ", b = " + b + // " and c = " + c); // Practice Math functions // double x = 4.6; // double y = 7.2; // System.out.println("rounding x gives " + Math.round(x)); // System.out.println("strange expression = " + // Math.min(Math.floor(x), Math.ceil(y))); // Practice Character functions // char ch = 'g'; // System.out.println("uppercase is " + Character.toUpperCase(ch)); // System.out.println("is letter? " + Character.isLetter(ch)); // UNCOMMENT THIS LAST PART TO PRACTICE SPECIAL WAYS TO // CHANGE VARIABLES // Practice with shortcuts for assignment // a = 4; // b = 3; // c = 2; // System.out.println("b += c returns " + (b += c)); // System.out.println("a -= b returns " + (a -= b)); // System.out.println("c *= a + b returns " + (c *= a + b)); // Practice with incrementer / decrementer // a = 4; // b = 3; // c = 2; // System.out.println("--c returns " + (--c)); // System.out.println("++a returns " + (++a)); // System.out.println("a * --b + c++ returns " + (a * --b + c++)); // System.out.println("final values of a,b,c are: " + a + " " + // b + " " + c); } }