Java Stdin and Stdout II

Sort by

recency

|

1202 Discussions

|

  • + 0 comments

    import java.util.Scanner;

    public class Solution {

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

    why this does not work? can anyone please explain, i have nextLine() before nextInt() then also String is not printed

    } }

  • + 0 comments

    why used scan.nextLine(); eis empty after double

  • + 0 comments

    Answer:

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

    }

  • + 0 comments
    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

    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);
        scan.close();
    
    }
    

    }