scan.nextLine() does not work after scan.nextDouble() in java

22 Views Asked by At

I want to take 3 inputs of an integer, double and string, so i wrote the following 3 lines:

    Scanner scan = new Scanner(System.in);
    int i = scan.nextInt();
    double d = scan.nextDouble();
    String s = scan.nextLine();

and to output:

    System.out.println("String: " + s);
    System.out.println("Double: " + d);
    System.out.println("Int: " + i);

I expected the output to be:

  String: Welcome!
  Double: 3.1415
  Int: 42

but I get an output:

  String: 
  Double: 3.1415
  Int: 42
0

There are 0 best solutions below