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. }
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]

donate a cup of tea :)

Join Our Facebook Group

Share this solution


Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube