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