Java Stdin and Stdout II

Sort by

recency

|

1228 Discussions

|

  • + 0 comments

    For Java15 Platform

    I wrote the code from scratch just to get more practice

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

    A more resilient solution capable of handling multiple empty lines before string

    import java.util.Scanner;

    public class Solution {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int i = scan.nextInt();
      String tokens = scan.nextLine();
      double d = scan.nextDouble();
    
        String s = "";
    
        while(scan.hasNextLine()){
        String input = scan.nextLine();
        if(!input.isEmpty()){
            s = input;
            break;
        }
        }
        scan.close();
    
        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); 
    
       }
             }
    

    }

  • + 0 comments

    Java remains one of the most powerful and versatile programming languages—great for everything from web apps to enterprise solutions. t20exchange login

  • + 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(); // This consumes the leftover newline after the double
        String s = scan.nextLine();
    
        System.out.println("String: " + s);
        System.out.println("Double: " + d);
        System.out.println("Int: " + i);
    }
    

    }