We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I had the same issue and tried the approach above, which didn't work for me. Instead, I added a new string (namely String e in my code) and it worked. I think the reason why it worked is because you need it to read the empty space as a string that won't return anything. That way, once it gets to read String s, it can have access to the next line which contains the actual string we want to output. See code below:
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int x=sc.nextInt();
double y =sc.nextDouble();
String e= sc.nextLine();
String s=sc.nextLine();
System.out.println("String: "+s);
System.out.println("Double: "+y);
System.out.println("Int: "+x);
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Stdin and Stdout II
You are viewing a single comment's thread. Return to all comments →
I had the same issue and tried the approach above, which didn't work for me. Instead, I added a new string (namely String e in my code) and it worked. I think the reason why it worked is because you need it to read the empty space as a string that won't return anything. That way, once it gets to read String s, it can have access to the next line which contains the actual string we want to output. See code below: import java.util.Scanner;
public class Solution {
}