I am using a Scanner class for input String variable but when I use nextLine() for two variable 2nd one is working fine but first one is not working. When I use another Scanner class object then input is working fine. What is the reason behind this?
import java.util.Scanner;
class Demo{
public static void main (String ... s )
{
Scanner scan=new Scanner(System.in);
int i;
System.out.println("Enter Number:");
i=scan.nextInt();
String name;
System.out.println("Enter String:");
name=scan.nextLine();
String second_name;
System.out.println("Enter 2nd String:");
second_name=scan.nextLine();
System.out.println(i);
System.out.println(name);
System.out.println(second_name);
}
}