Java Stdin and Stdout II

  • + 0 comments
    import java.io.*;
    import java.util.*;
    
    public class Solution {
    
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int myInt = sc.nextInt();
            double myDouble = sc.nextDouble();
            
            String myString = "";
            // using hasNext we can find out if there's anymore inputs
            while(sc.hasNext()){
                // nextLine() returns the string till EOL instead of the next space
                myString += sc.nextLine();
            }
            
            System.out.println("String: "+myString);
            System.out.println("Double: "+myDouble);
            System.out.println("Int: "+myInt);
        }
    }