Java Stdin and Stdout II

Sort by

recency

|

1185 Discussions

|

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

    }

  • + 0 comments

    Simply take all the inputs in string and convert them to their respective data types before printing through type casting.

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

  • + 0 comments

    import java.util.*; import java.math.BigDecimal;

    public class Solution {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s="";
        int c=0;
        String[] arr = new String[3];
    
        // double d = scan.nextInt();
        // int i = scan.nextInt();
    
        while(scan.hasNext()) {
            s = scan.nextLine();
    
          arr[c]= s;
    
               c++;
        }
    
        for (int i = arr.length; i >= 0;i--) {
           if (i==2) {
                System.out.println("String: " + arr[i]);
            } else if (i==1) {
                System.out.println("Double: " + 
                Double.parseDouble(arr[i]));
            }  else if (i==0) {
                System.out.println("Int: " + arr[i]);
            } 
        }
    
    
        // Write your code here.
    
    
    
    
    
    
    }
    

    }

  • + 0 comments

    Hi @Everyone can you please explain me how they are take input without any code

  • + 1 comment
    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.next();
            String s =scan.nextLine();
            // Write your code here.
    
            System.out.println("String: " + s);
            System.out.println("Double: " + d);
            System.out.println("Int: " + i);
        }
    }