Java Stdin and Stdout II

  • + 1 comment

    Without scan.nextLine() not read from your next line.

    if your input is:

    42
    3.1415 Welcome to HackerRank's Java tutorials!
    

    the output is:

    String:  Welcome to HackerRank's Java tutorials!
    Double: 3.1415
    Int: 42
    

    So this time the output is correct but the input is not.

    Check the box " Test against custom input" and play yourself.

    Also next code works

    import java.util.Scanner;
    
    public class Solution {
    
        public static void main(String[] args) {
            Scanner scan = new Scanner(System.in);
            int i = scan.nextInt();
            scan.nextLine();
            Double d = scan.nextDouble();
            scan.nextLine();
            String s = scan.nextLine();
        
            System.out.println("String: " + s);
            System.out.println("Double: " + d);
            System.out.println("Int: " + i);
        }
    }