Java Stdin and Stdout II

Sort by

recency

|

1223 Discussions

|

  • + 0 comments

    public static void main(String[] args) { Scanner scan = new Scanner(System.in); int i = scan.nextInt(); Double d = scan.nextDouble(); scan.nextLine(); String s = scan.nextLine(); // Write your code here.

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

    The solution is:

    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();
        scan.nextLine(); // this is the focus point 
        String s = scan.nextLine();
    
        System.out.println("String: " + s);
        System.out.println("Double: " + d);
        System.out.println("Int: " + i);
    }
    

    }

  • + 0 comments

    **This is Correct code , passed all test cases. ** 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();
          s = scan.nextLine();
    
        // Write your code here.
    
        System.out.println("String: " + s);
        System.out.println("Double: " + d);
        System.out.println("Int: " + i);
    }
    

    }

  • + 0 comments

    How this test case getting passed. Im confused can someone explain this.

    Compiler Message Success

    Input (stdin)

    2147483647 235345345345.234534 fsdfsdf sdf

    Expected Output

    String: fsdfsdf sdf Double: 2.3534534534523453E11 Int: 2147483647

  • + 0 comments

    This was my original solution:

    public class Solution {
    
        public static void main(String[] args) {
            try{
                Scanner scan = new Scanner(System.in);
                int i = scan.nextInt();
                double d =scan.nextDouble();
                scan.useDelimiter("\n");
                String s = scan.next();
                scan.close();
    
                System.out.println("String: " + s);
                System.out.println("Double: " + d);
                System.out.println("Int: " + i);            
            }catch(Error e){
                System.out.println("something went wrong:" +e);
            }
    
        }
    }
    

    I'm not really sure why this doesnt satisfy the test cases, although it prints as expected