// IntegerClassTests.java (c) 2005 Kari Laitinen // http://www.naturalprogramming.com // 2005-05-16 File created. // 2005-05-22 Last modification. // This program tests the Integer class which is one of the // standard wrapper classes of Java. // The "bitwise" Integer methods are tested in program // BinaryWithWrappedInt.java. import java.util.* ; class IntegerClassTests { public static void main( String[] not_in_use ) { Scanner keyboard = new Scanner( System.in ) ; int some_int_variable = 77 ; Integer some_integer_object = new Integer( some_int_variable ) ; int another_int_variable = 88 ; Integer another_integer_object = another_int_variable ; Integer third_integer_object = 99 ; Object object_to_print = third_integer_object ; System.out.print( "\n " + object_to_print + "\n " ) ; some_integer_object = another_integer_object + third_integer_object ; System.out.print( some_integer_object ) ; int result_as_int_variable = another_integer_object + third_integer_object + 4000 ; System.out.print( "\n " + result_as_int_variable + "\n") ; System.out.print( "\n Integer.MAX_VALUE is " + Integer.MAX_VALUE ) ; System.out.print( "\n Integer.MIN_VALUE is " + Integer.MIN_VALUE ) ; System.out.print( "\n Integer.TYPE is " + Integer.TYPE + "\n" ) ; // "11" is interpreted below as decimal, hexadecimal, and binary string. System.out.print( "\n " + Integer.parseInt( "11" ) ) ; System.out.print( "\n " + Integer.parseInt( "11", 16 ) ) ; System.out.print( "\n " + Integer.parseInt( "11", 2 ) ) ; // The value of some_int_variable is printed in decimal, hexadecimal // and binary form. System.out.print( "\n\n " + Integer.toString( some_int_variable ) + " " + Integer.toHexString( some_int_variable ) + " " + Integer.toBinaryString( some_int_variable )); // The same is done again with the toString() methods. System.out.print( "\n\n " + Integer.toString( some_int_variable ) + " " + Integer.toString( some_int_variable, 16 ) + " " + Integer.toString( some_int_variable, 2 )); System.out.print( "\n " + Integer.decode( "0x41" ) ) ; } }