Results 1 to 3 of 3
  1. #1
    mcollins is offline Member
    Join Date
    Mar 2009
    Posts
    5
    Rep Power
    0

    Default How to make Scanner read the same line

    Hello,

    I'm like to know how to make the 'Scanner' read the same line as the outputted text before it. i.e. askes a question, the user types the question on the same line and the scanner reads their input.

    Below is what I've written so far:

    Java Code:
       
                System.out.println("Please enter a number? ");
                int Number;
                Scanner myScanner = new Scanner(System.in);
                Number = myScanner.nextInt();
    The output should look something like this...

    Please enter a number? 10

    and then it gaves Number a value of 10.

    Thanks.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Sure. Don't use System.out.println, use System.out.print instead.

  3. #3
    mcollins is offline Member
    Join Date
    Mar 2009
    Posts
    5
    Rep Power
    0

Similar Threads

  1. Using Scanner class to read int value
    By Java Tip in forum Java Tip
    Replies: 1
    Last Post: 02-07-2009, 02:47 AM
  2. Replies: 0
    Last Post: 04-17-2008, 07:36 PM
  3. Reading a line from console using Scanner class
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-18-2008, 11:52 AM
  4. Using Scanner class to read int
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-18-2008, 11:50 AM
  5. Read from console (Scanner Class)
    By hey in forum New To Java
    Replies: 10
    Last Post: 12-11-2007, 10:11 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
  •