Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 1 of 1

Thread: Scanner multipule input [Solved]

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Scanner multipule input [Solved]

    Hello all,

    I'm having a bit of trouble using a Scanner, it'll get the typed information right up until the last two, where it decides to skip "Please enter your town:" and ask for "Please enter your postcode:" instead, though it'll still show "Please enter your town:" in the console (I just can't enter a value into it) every other input seems to go through fine.

    Can anyone be of assistance and inform me as to why this is happening? Logic tells me that it's a problem using multiple inputs, perhaps even a problem when the input is changed from String to integer - But I'm hitting my head off the desk in frustration

    Update: It appears my problem was solved by creating one scanner for strings and the other for integers.

    Code updated:
    import java.util.Scanner;
     
    public class week3b
    {
    	public static void main(String[] args)
    	{
    		Scanner input = new Scanner(System.in);
    		Scanner integer = new Scanner(System.in);
    		System.out.println("Please enter your title:");
    		String title = input.nextLine();
    		System.out.println("Please enter your forename:");
    		String forename = input.nextLine();
    		System.out.println("Please enter your surname:");
    		String surname = input.nextLine();
    		System.out.println("Please enter your house number:");
    		int housenumber = integer.nextInt();
    		System.out.println("Please enter your street name:");
    		String street = input.nextLine();
    		System.out.println("Please enter your town:");
    		String town = input.nextLine();
    		System.out.println("Please enter your post code:");
    		String postcode = input.nextLine();
    		System.out.println("Your postal address is:");
    		System.out.println("\n"+title+" "+forename+", "+surname+" ");
    		System.out.println("\n"+housenumber+" "+street+", ");
    		System.out.println("\n"+town+",");
    		System.out.println("\n"+postcode+"");
    	}
     
    }

    Thank you for your time,

    Dragon-RD
    Last edited by Dragon-RD; October 17th, 2013 at 09:47 AM. Reason: Somewhat got round to fixing my code.


Similar Threads

  1. Java user input troubles using the scanner class
    By Lach in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 9th, 2013, 11:13 AM
  2. File input using Scanner help.
    By AaronHarris in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 4th, 2013, 07:15 AM
  3. Scanner skipping input
    By hblakek in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: February 21st, 2012, 01:44 PM
  4. Reading user input from the console with the Scanner class
    By JavaPF in forum Java SE API Tutorials
    Replies: 3
    Last Post: September 7th, 2011, 03:09 AM
  5. Reading user input from the console with the Scanner class
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: November 11th, 2008, 02:47 PM