Wednesday, 2 October 2013

How to accept different data types from the user in java

How to accept different data types from the user in java

I'm a beginner in Java and I just wrote a program to get the user's name,
phone number and address. The problem is after reading the phone number
the program will not proceed to read the address, it's like if it's
skipping it. Here is my code:
public static void main(String [] arge){
Scanner sc = new Scanner(System.in);
System.out.println("Enter your name, phone number and address");
String name = sc.nextLine();
long phone = sc.nextLong();
String address = sc.nextLine();
System.out.println("\n *** Here is your info ***");
System.out.println("Name: "+name+"\nPhone number: "+phone+"\n Address:
"+address);
}

No comments:

Post a Comment