Java Stdin and Stdout II

Sort by

recency

|

1194 Discussions

|

  • + 0 comments

    import java.util.*;

    public class Solution {

    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int i=in.nextInt();
        double d=in.nextDouble();
        in.nextLine();
        String s=in.nextLine();
        System.out.println("String: "+s +"\n"+"Double: "+d+"\n"+"Int: "+i+"\n");
        in.close();
    }
    

    }

  • + 0 comments

    Aca les dejo mi solucion ya que el String me devolvia una cadena vacia, lo que hice fue ponerlo dos veces de entre las lineas scan.nextInt y scan.nextDouble,

    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);
    }
    

    }

  • + 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);
    }
    

    }

  • + 1 comment

    Solution:

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int i = scan.nextInt();
        Double d = scan.nextDouble();
        scan.nextLine();  // adding this as after reading double value it adds \n  to indicate end of buffer to the scan 
        //so reads the same  empty string if we dont mention
                //so above that /n is consumed
        String s=scan.nextLine();
    
        // Write your code here.
    
        System.out.println("String: " + s);
        System.out.println("Double: " + d);
        System.out.println("Int: " + i);
    }
    

    }

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

    }