Java End-of-fileby Shafaet
- Problem
- Submissions
- Leaderboard
- Discussions
- Editorial
"In computing, End of File (commonly abbreviated EOF) are a condition in a computer operating system wher e No more data can is read from a data source. "-(Wikipedia:end-of-file)
the challenge are to read lines of input until you reach EOF, then number and print all lines of CO Ntent.
Hint: The Java ' s scanner.hasnext () method is the helpful for this problem.
Input Format
Read some unknown lines of input from stdin (system.in) until your reach EOF; each line of input cont Ains a non-empty String.
Output Format
For each line, print the line number, followed by a single space, and then the line content received as input.
Sample Input
Hello worldI am a fileRead me until end-of-file.
Sample Output
1 Hello world2 I am a file3 Read me until end-of-file.
Import java.util.*;import java.io.*;import java.text.*;import java.math.*;import java.util.regex.*;class Main{ public static void Main (string[] args) { Scanner scan = new Scanner (system.in); for (int i = 1; scan.hasnext (); i++) { System.out.println (i + "+ scan.nextline ())} } Sc.close (); }
The use of Java Hasnext ()