/* * Test of local variables */ public class LocalTest { /* COMPILATION ERROR - commented out */ /* public static void dumb( int y ) { do { double z = Math.random( ); System.out.println( "z = " + z ); } while ( --y > 0 ); System.out.println( "In dumb: z = " + z ); // ERROR: z cannot be resolved } */ /* COMPILATION ERROR - commented out */ /* public static void dumber( int y ) { int y; // ERROR: Duplicate variable y double z; do { double z = Math.random( ); // ERROR: Duplicate variable z System.out.println( "z = " + z ); } while ( --y > 0 ); System.out.println( "In dumber: z = " + z ); } */ public static void smarter( int y ) { double z; do { z = Math.random( ); System.out.println( "z = " + z ); } while ( --y > 0 ); System.out.println( "In smarter: z = " + z + " y = " + y ); } }