// Author: Kiri Wagstaff, wkiri@cs.cornell.edu // Date: June 28, 2001 public class Lecture4 { public static void main(String[] args) { int temperature = 3; boolean b = 3 < 4; // Type casting System.out.println((int)9.8); System.out.println((char)88); // This "works", but is bad style: System.out.println((char)88.3); System.out.println((int)'X'); // The following will not compile (errors!): // System.out.println((int)"Hi"); // System.out.println((boolean)3); // *Do* try this at home. // Booleans and comparison operators // int a, b, c; // Check whether a, b, c are in sorted order // boolean isSorted = (a < b) && (b < c); // comment // boolean allSame = (a == b) && (b == c); // boolean allDifferent = (a != b) && (b != c) && (a != c); // Won't cover all cases: // boolean allDifferent = !allSame; // Nested if statements if (temperature < 100) { if (temperature > 80) { System.out.println("It's hot!"); } else { System.out.println("Not so hot."); } } } }