Java Stdin and Stdout II

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

    }