/* * Snippets for Chapt 29 */ import java.util.*; public class Chapt29Snippets { public static void main(String[] args) { System.out.println( absValue1(2)); System.out.println( absValue1(-2)); System.out.println( absValue2(2)); System.out.println( absValue2(-2)); test1(); } public static int absValue1( int x ) { if ( x < 0 ) return -x; else return x; } public static int absValue2( int x ) { return (x < 0 ? -x : x); } public static void test1( ) { double x = 0, y = 1; double max = (x > y) ? x : y ; String s = "hello"; double z = 32.4; double x2 = s.equals("zero") ? 0.0 : 3*(z + 13.2); } }