Why do I need to put sc.nextLine();
? I tried without it, but the string just could not catch my input.
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Please enter integer, double and string");
int x=sc.nextInt();
double y=sc.nextDouble();
sc.nextLine();
String s=sc.nextLine();
//Complete this code
System.out.println("String: "+s);
System.out.println("Double: "+y);
System.out.println("Int: "+x);
}
}