Below is the code :
import java.util.Scanner;
public class Calculate{
public static void main(String args[])
{
int age=0;
String name="";
Scanner scan=new Scanner(System.in);
System.out.println("Please Enter value of your age : ");
age=scan.nextInt();
System.out.println("Please Enter value of your name : ");
name=scan.nextLine();
System.out.println("Age : "+age+", Name : "+name);
}
}
Now, Here the issue is taking String value from the user.
I can take two INTEGER
values from user one by one after pressing [ENTER]
.
But, In case of taking STRING
value from the user Second time, It just let me out after I enter value for Age variable.
If I first take the input for String
and then INTERGER
than it working fine as below : (First name and then age) :
System.out.println("Please Enter value of your name : ");
name=scan.nextLine();
System.out.println("Please Enter value of your age : ");
age=scan.nextInt();
What might be the issue ?