Java End-of-file

  • + 1 comment

    Using stream

    import java.util.*;
    import java.util.stream.*;
    
    public class Solution {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            IntStream.iterate(1, n -> n + 1)
                     .takeWhile(n -> sc.hasNextLine())
                     .forEach(n -> System.out.println(n + " " + sc.nextLine()));
            sc.close();
        }
    }