I had a doubt on how to use java.io.read(). How it works

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rajtilak
    New Member
    • Jul 2010
    • 1

    #1

    I had a doubt on how to use java.io.read(). How it works

    When I try to read a value and print it its not projecting the same i dont understand what is the mistake i am giving the code which i tried to compile

    Code:
    import java.io.IOException;
    
    class Toread
        {
    	  public static void main(String args[]) 
    	      {
    		      int x;
    	     System.out.println("Enter a digit");
    	          try
    	          {
    		    x= System.in.read();
    	      System.out.println("Entered Value:"+x);
                      }
    		  catch(IOException e)
    		  {
    	      System.out.println("You had entred wrong value");
    				}
    		   }		
                     			 
         }
    When i try to compile the output is this way
    Enter a digit: 1
    Entered Value :50
    Last edited by Niheel; Jul 12 '10, 04:19 PM.
Working...