Problem Of Scanner Object with its method nextLine()
Hy . . .
Here is the code . . .
problem is that i when run this program, it works smoothly until of taking integer input after that it doent ask me to give input of string for first name and skip it then ask for the lastName immediately after prompting ??
public class abc
public static void main ( String args )
Scanner input = new Scanner( System.in );
String firstName, lastName;
int num1, num2;
System.out.print( "Enter first number: " );
num1 = input.nextInt();
System.out.print( "Enter second number: " );
num2 = input.nextInt();
System.out.printf( "Sum is %dn", num1 + num2 );
System.out.print( "Enter first name: " );
firstName = input.nextLine();
System.out.print( "Enter last name: " );
lastName = input.nextLine();
System.out.printf( "Your full name is %s %s", firstName, lastName );
Have you know what the problem it is ??
Output like this . . .
Enter first number: 1
Enter second number: 1
Sum is 2
Enter first name: Enter last name: Storm
Your full name is Storm
Thanks . . .:)