import java.io.*;  // needed for BufferedReader, InputStreamReader, etc.

/** A Java program that demonstrates console based input and output. */
public class JavaIOExample 
{
    // Create a single shared BufferedReader for keyboard input
    private static BufferedReader stdin = 
        new BufferedReader( new InputStreamReader( System.in ) );

    // Program execution starts here
    public static void main ( String [] args ) throws IOException
    {
    	//Example of reading in a line of text from the keyboard
    	
        // Prompt the user
        System.out.print( "Type some data for the program: " );

        // Read a line of text from the user.
        String input = stdin.readLine();

        // Display the input back to the user.
        System.out.println( "input = " + input );
        
        /*****************/
        
        //Example of reading in an integer from the keyboard
        
        // Prompt the user for an integer
        System.out.print( "Type an integer: " );
        
        // Read in the input
        input = stdin.readLine();
        
       	// converts a String into an int value
        int myIntegerVariable = Integer.parseInt( input );  
        
        // Display the integer back to the user.
        System.out.println( "integer = " + myIntegerVariable );
       
        /*****************/
       
        //Example of reading in a double from the keyboard
       
        // Prompt the user for an double
        System.out.print( "Type a double: " );

        // Read in the input
        input = stdin.readLine();
              	       
       	// converts a String into an int value
        double myDoubleVariable = Double.parseDouble( input );  
        
        // Display the integer back to the user.
        System.out.println( "double = " + myDoubleVariable );
        
        /*****************/
        
	//Example of using an if-statement
		
	if (myIntegerVariable > myDoubleVariable)
	{
		System.out.println(myIntegerVariable + " is greater than " 
			+ myDoubleVariable);
	}
	else
	{
		System.out.println(myIntegerVariable + " is NOT greater than " 
			+ myDoubleVariable);
	}
	
	/*****************/
       
	//Example of using a while statement
	
	int counter = 0;
	
	//while loop runs myIntegerVariable times
	while (counter < myIntegerVariable)
	{
		//prints out the current value of counter
		System.out.println("while loop counter => " + counter);
		counter++;
	}
	
	/*****************/
       
	//Example of using a for statement
	
	//for loop runs myIntegerVariable times
	//for ( initialize ; condition ; action )
	for (counter = 0; counter < myIntegerVariable; counter++)
	{
		//prints out the current value of counter
		System.out.println("for loop counter => " + counter);
	}

    } // end main method

} // end MyConsoleIO class
