I want a program in java to accept
1.Integer
2.Double
3.String respectively . and display the above .
But the problem I m facing is after I enter integer and double its not prompting me to enter String . Its directly display the values . As i searched the soln to this , I got to know that
scan.nextLine();
should be used after I accept the double value .
can anyone tell me why should use this line . I read the doc of nextLine . But I didnt understand .
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int i = scan.nextInt();
double d = scan.nextDouble();
// scan.nextLine(); **Why should I write this ??**
String s = scan.nextLine();
System.out.println("String: " + s);
System.out.println("Double: " + d);
System.out.println("Int: " + i);
}
}