I am not able to use nextLine
method after using nextInt
method.This is the note given below....
note in hacker rank:(If you use the nextLine()
method immediately following the nextInt()
method, recall that nextInt()
reads integer tokens; because of this, the last newline character for that line of integer input is still queued in the input buffer and the next nextLine()
will be reading the remainder of the integer line (which is empty).
The nextLine method is not getting skiped but it is empty.
Code:
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();
String s=scan.nextLine();
// Write your code here.
System.out.println("String: " + s);
System.out.println("Double: " + d);
System.out.println("Int: " + i);
}
}
Output: String: Double: 3.1415 Int: 42