Here is my code:
public class Solution { public static void main(String[] args) { /* * Enter your code here. Read input from STDIN. * Print output to STDOUT. * Your class should be named Solution. */ int num = 0; double dou = 0.0; String s = null; Scanner in = new Scanner(System.in); if (in.hasNextInt()) { num = in.nextInt(); } Scanner d = new Scanner(System.in); if (d.hasNextDouble()) { dou = d.nextDouble(); } Scanner str = new Scanner(System.in); if (str.hasNextLine()) { s = str.nextLine(); } System.out.println("String:" + s); System.out.println("Double:" + dou); System.out.println("Int:" + num); } } I am getting this output:
String:null
Double:0.0
Int:42
But it should should look like this:
String: Welcome to Hackerrank Java tutorials!
Double: 3.1415
Int: 42
Can anyone explain me why I'm getting a null value for the string and 0.0 for the double?
Intvalue, then enter, thenDoublevalue, enter, and thenStringvalue