Hi,
I'm new to this Java world, and just can't figure out this problem. After I use nextInt or nextDouble, and try to use nextLine, it won't work unless I put nextLine twice. What's the problem there, and what would be the good way to handle this?
Just gave a code to illustrate a simple example I can understand.
import java.util.Scanner;
public class nextLineProblem {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Type in something for line 1");
String line1 = sc.nextLine();
System.out.println("Type an integer for line 2");
int line2 = sc.nextInt();
System.out.println("Type in something for line 3");
String line3 = sc.nextLine();
System.out.println("Line1: " + line1 + "\n" + "Line2: " + line2 + "\n" + "Line3:" + line3);
}
}