Results 1 to 5 of 5

Thread: Java - scanner package for user input

  1. #1
    Join Date
    Aug 2009
    Posts
    155

    Java - scanner package for user input

    Hello,
    Here is a problem, I want to read data from keyboard in java. I work in back, I wrote a small program when compiling no problem but then the execution an exception this product. If you have an sample code regarding the same then please let me know. Thanks for your replies.

  2. #2
    Join Date
    Mar 2010
    Posts
    197

    Re: Java - scanner package for user input

    Hello,
    Try the following code
    Code:
    import java.io. *; 
    
    class test 
    public static void main (String [] args) throws IOException ( 
    BufferedReader kb = new BufferedReader (new InputStreamReader (System.in)); 
    
    
    int rw, clm; 
    System.out.println ("please input the number of rows:"); 
    
    rw = Integer.parseInt (temp.readLine ()) / / reading the entire 
    System.out.println ("please input the number of columns:"); 
    
    clm = Integer.parseInt (temp.readLine ()) / / reading the entire 
    ) 
    )
    See if this can help you How to read user input from console using Scanner class in java?

  3. #3
    Join Date
    Nov 2009
    Posts
    359

    Re: Java - scanner package for user input

    This is the main part of your code
    Code:
    BufferedReader = new BufferedReader kb (new InputStreamReader (System.in)); 
    String cm = ""; 
    System.out.println ("please enter the number of columns:"); 
    try ( 
    kb.readLine cm = (); 
    ) 
    catch (IOException e) ( 
    System.out.println ("Error"); 
    ) 
    try ( 
    int cm = Integer.parseInt (cm); 
    ) 
    catch (IOException e) (
    System.out.println ("you have input, a string of characters, re veuillee input a number"); 
    )

  4. #4
    Join Date
    Dec 2009
    Posts
    292

    Re: Java - scanner package for user input

    Take for example the case

    Code:
    try 
    ( 
    int ln = Integer.parseInt (ln); 
    ) 
    catch (IOException e) (
    System.out.println ("you have input, a string of characters, input a number"); 
    )
    This is the basic structure of the code

  5. #5
    Join Date
    Mar 2010
    Posts
    200

    Re: Java - scanner package for user input

    I tried the above as you have explained in the post. Always the same mistake it did not change, thank you for your help, for the code I gave the class with a scanner which has found what is wrong? I do not know what exactly is wrong with scanner, if you guys know any alternate method then please let me know. Thank you.

Similar Threads

  1. How to read user input from console using Scanner class in java?
    By Constantinee in forum Software Development
    Replies: 4
    Last Post: 06-02-2010, 06:47 PM
  2. JAVA Fundamental: The java.io package
    By TechyGuy in forum Guides & Tutorials
    Replies: 4
    Last Post: 05-02-2010, 02:14 PM
  3. How to use Console class to read user input in java?
    By MABON in forum Software Development
    Replies: 4
    Last Post: 04-02-2010, 10:17 PM
  4. how to get user input with char value in java
    By Bearer in forum Software Development
    Replies: 5
    Last Post: 07-01-2010, 05:51 PM
  5. How to package in java
    By nanakofiboafo in forum Software Development
    Replies: 3
    Last Post: 22-04-2009, 08:29 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,500,300.63887 seconds with 16 queries