/** * Some examples of expressions * * @author Bhaskaran Raman * @version 06 Jan 2005 */ public class Expr { public static void main(String[] args) { System.out.print("2 < 3 is "); System.out.println(2 < 3); String s1 = "abc"; String s2 = "abc"; System.out.print("s1 == s2 is "); System.out.println(s1 == s2); String s3 = null; System.out.print("(2 == 3) && s3.equals(s1) is "); System.out.println((2 == 3) && s3.equals(s1)); int x = 256; System.out.println("x is " + x); System.out.println("x << 3 is " + (x << 3)); System.out.println("x >> 1 is " + (x >> 1)); System.out.println("-x >> 1 is " + (-x >> 1)); System.out.println("-x >>> 1 is " + (-x >>> 1)); x /= 2; System.out.println("x after x /= 2 is " + x); x++; System.out.println("x after x++ is " + x); System.out.print("(2 < 3) ? 6 : 7 is "); System.out.print((2 < 3) ? 6 : 7); } // End main() static boolean odd(int n) { if((n%2) == 1) { return true; } else { return false; } } // End odd() public String reverse(String s1) { int len = s1.length(); String rev = ""; int i; for(i = len-1; i >= 0; i--) { char c1 = s1.charAt(i); rev += String.valueOf(c1); } return rev; } // End reverse() public int gcd(int x, int y) { if(x < y) { int temp = x; x = y; y = temp; } while((x%y) != 0) { int rem = x%y; x = y; y = rem; } return y; } } // End class Expr