HackerRank Java- End-of-file
The challenge here is to read n lines of input until you reach EOF, then number and print all n lines of content.
- import java.io.*;
- import java.util.*;
- import java.text.*;
- import java.math.*;
- import java.util.regex.*;
-
- public class Solution {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int i = 1;
- while (scan.hasNextLine()) {
- System.out.println(i + " " + scan.nextLine());
- i++;
- }
- scan.close();
- }
- }