Results 1 to 2 of 2
  1. #1
    Java Tip's Avatar
    Java Tip is offline Moderator
    Join Date
    Nov 2007
    Posts
    1,694
    Blog Entries
    430
    Rep Power
    9

    Default Using Scanner class to read int value

    Scanner class is used to read input from console. Following code segments takes an integer value from the user through console.

    Java Code:
    Scanner inputScanner = new Scanner(System.in);
    int n = inputScanner.nextInt();

  2. #2
    oteggis is offline Member
    Join Date
    Feb 2009
    Posts
    1
    Rep Power
    0

    Default

    Scanner inputScanner = new Scanner(System.in);
    int n = inputScanner.nextInt();

    Can I use the statements below to convert a String to an integer?
    String strInput = JOptionPane.showInputDialog("Hello");
    n = Integer.parseInt(strInput);

Similar Threads

  1. Getting tokens using Scanner class
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-05-2008, 09:11 AM
  2. Using Scanner class to read int
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-18-2008, 11:50 AM
  3. Read from console (Scanner Class)
    By hey in forum New To Java
    Replies: 10
    Last Post: 12-11-2007, 10:11 PM
  4. Scanner class
    By ajaymenon.k in forum Advanced Java
    Replies: 1
    Last Post: 11-26-2007, 07:01 AM
  5. JDK 5.0 Scanner Class
    By Sircedric88 in forum New To Java
    Replies: 3
    Last Post: 07-27-2007, 06:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •