// Javatests.java (c) 2004 Kari Laitinen // http://www.naturalprogramming.com // 2005-04-05 File created. // 2005-08-09 Last modification. // This file has been used to write short programs that // test various Java features. The test programs are put to // comments after they a no longer needed. import java.util.* ; class Javatests { public static void main( String[] not_in_use ) { } } /******* class SomeClass { int some_integer_field = 9 ; double some_number = 33.44 ; String some_string_field = "initial text" ; int[] some_integer_array = { 66, 77, 88 } ; public SomeClass( int given_value ) { some_integer_array[ 1 ] = given_value ; } public SomeClass() { this( 33 ) ; System.out.print( "\n Default constructor executed." ) ; } public void print() { System.out.print( "\n array element: " + some_integer_array[ 1 ] ) ; System.out.print( "\n string " + some_string_field ) ; } } class Javatests { public static void main( String[] not_in_use ) { Scanner keyboard = new Scanner( System.in ) ; SomeClass some_object = new SomeClass() ; some_object.print() ; Calendar birth_of_winston_churchill = new GregorianCalendar( 1874, 10, 30 ) ; Calendar birth_of_charles_darwin = new GregorianCalendar( 1809, 1, 9, 14, 39, 48 ) ; System.out.printf( "\n %tc", birth_of_winston_churchill ) ; System.out.printf( "\n %tc", birth_of_charles_darwin ) ; } } public static void main( String[] not_in_use ) { Scanner keyboard = new Scanner( System.in ) ; //System.out.print( "\n Give a hexadecimal number: " ) ; //String given_number_as_string = keyboard.nextLine() ; //int integer_from_keyboard = // Integer.parseInt( given_number_as_string, 16 ) ; //System.out.print( "\n " + integer_from_keyboard ) ; SomeClass some_object = new SomeClass() ; System.out.print( "" + some_object + "\n" ) ; String hexadecimal_string = String.format( "%X", 33 ); // String hexadecimal_string = Integer.toHexString( 33 ); System.out.print( hexadecimal_string ) ; System.out.print( "\n " + Integer.parseInt( "123" ) + " " + Integer.parseInt( "1111011", 2 ) + " " + Integer.parseInt( "7B", 16 ) ) ; String value_of_pi_as_string = "3.14159" ; double value_of_pi = Double.valueOf( value_of_pi_as_string ) ; // double value_of_pi = // Double.parseDouble( value_of_pi_as_string ) ; System.out.print( "\n\n " + value_of_pi + "\n\n ") ; long some_long = 999 ; int some_int = (int) some_long ; char some_character = 'A' ; System.out.print( (int) some_character ) ; } public static void main( String[] not_in_use ) { Scanner keyboard = new Scanner( System.in ) ; int some_integer = 112 ; int some_other_integer = 622 ; System.out.printf( "\n" ) ; System.out.printf( "The value is %d.", some_integer ) ; System.out.printf( "\n" ) ; System.out.printf( "The values are %d and %d.", some_integer, some_other_integer ) ; System.out.printf( "\n" ) ; System.out.printf( "%1$d is %1$d, but %1$d is not %2$d", some_integer, some_other_integer ) ; System.out.printf( "\n" ) ; System.out.printf( " %1$d is %1$d.", some_integer ) ; } public static void main( String[] not_in_use ) { Scanner keyboard = new Scanner( System.in ) ; int sum_of_integers = 0 ; boolean user_wants_to_stop_entering_numbers = false ; while ( user_wants_to_stop_entering_numbers == false ) { System.out.print( "\n Give a number: " ) ; int integer_from_keyboard = keyboard.nextInt() ; if ( integer_from_keyboard == 9999 ) { user_wants_to_stop_entering_numbers = true ; } else { sum_of_integers = sum_of_integers + integer_from_keyboard ; } } System.out.print( "\n The sum is " + sum_of_integers ) ; System.out.print( "\n Enter a character and press Enter: " ) ; char character_from_keyboard = keyboard.nextLine().charAt( 0 ) ; System.out.print( "\n The code of the character " + character_from_keyboard + " is " + (int) character_from_keyboard ) ; System.out.print( "\n Enter another character and press Enter: " ) ; character_from_keyboard = keyboard.nextLine().charAt( 0 ) ; System.out.print( "\n The code of the character " + character_from_keyboard + " is " + (int) character_from_keyboard ) ; System.out.print( "\n Enter a hexadecimal number: " ) ; int integer_from_keyboard = keyboard.nextInt( 16 ) ; System.out.print( "\n You entered: " + integer_from_keyboard + "\n" ) ; } public static void main( String[] not_in_use ) { Scanner keyboard = new Scanner( System.in ) ; // tests related to arrays in Java int[] days_in_months = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } ; for ( int month_index = 0 ; month_index < days_in_months.length ; month_index ++ ) { System.out.print( " " + days_in_months[ month_index ] ) ; } double[] us_gallons_to_liters = new double[] { 0.0, 3.785, 7.570, 11.355, 15.140, 18.925 } ; double[] us_gallons_to_liters_ = { 0.0, 3.785, 7.570, 11.355, 15.140, 18.925 } ; float[] liters_to_us_gallons = { 0.0F, 0.264F, 0.528F, 0.793F, 1.057F, 1.321F } ; char[] arithmetic_operators = { '+', '-', '*', '/', '%' }; int[] array_of_zeroes = new int[ 6 ] ; int[] array_of_zeroes_ = { 0, 0, 0, 0, 0, 0 } ; for ( int integer_index = 0 ; integer_index < array_of_zeroes.length ; integer_index ++ ) { System.out.print( " " + array_of_zeroes[ integer_index ] ) ; } int[][] matrix = new int[ 4 ] [ 5 ] ; matrix[ 0 ][ 0 ] = 1 ; matrix[ 0 ][ 4 ] = 1 ; matrix[ 3 ][ 0 ] = 1 ; matrix[ 3 ][ 4 ] = 1 ; int[][][] cube = new int[ 3 ] [ 4 ] [ 5 ] ; cube[ 0 ] [ 0 ] [ 0 ] = 1 ; cube[ 2 ] [ 3 ] [ 4 ] = 1 ; } public static void main( String[] not_in_use ) { Scanner keyboard = new Scanner( System.in ) ; String short_text_lines = "\n aaa \n bbb \n ccc " ; System.out.print( short_text_lines.length() ) ; int[] array_of_integers = new int[ 50 ] ; array_of_integers[ 52 ] = 88 ; array_of_integers[ 99 ] = 888 ; } // int enum = 4 ; // enum was reported to be a keyword int true = 3 ; int false = 4 ; true and false were not reported to be keywords. The following messages were printed when the above declarations were compiled. Javatests.java:18: not a statement int true = 3 ; ^ Javatests.java:18: ';' expected int true = 3 ; ^ Javatests.java:19: not a statement int false = 4 ; ^ Javatests.java:19: ';' expected int false = 4 ; ^ *****/