In this HackerRank Java End-of-file problem we need to read n lines of input until you reach EOF, then number and print all n lines of content.

HackerRank Java End-of-file problem solution

HackerRank Java End-of-file problem solution

import java.io.*;
import java.util.*;
import java.util.regex.*;

public class Solution {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int line_num = 0;
        while(sc.hasNext())
        	System.out.println(++line_num + " " + sc.nextLine());
        sc.close();

    }
}