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.



  1. import java.io.*;
  2. import java.util.*;
  3. import java.text.*;
  4. import java.math.*;
  5. import java.util.regex.*;
  6. public class Solution {
  7. public static void main(String[] args) {
  8. Scanner scan = new Scanner(System.in);
  9. int i = 1;
  10. while (scan.hasNextLine()) {
  11. System.out.println(i + " " + scan.nextLine());
  12. i++;
  13. }
  14. scan.close();
  15. }
  16. }

download android app