Java End-of-file
"In computing, End Of File (commonly abbreviated EOF) is a condition in a computer operating system where no more data can be read from a data source." — (Wikipedia: End-of-file)
The challenge here is to read <span class="MathJax" data-mathml="n" id="MathJax-Element-1-Frame" role="presentation" style="border: 0px; direction: ltr; display: inline; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; position: relative; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;" tabindex="0">n lines of input until you reach EOF, then number and print all <span class="MathJax" data-mathml="n" id="MathJax-Element-2-Frame" role="presentation" style="border: 0px; direction: ltr; display: inline; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; position: relative; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;" tabindex="0">n lines of content.
Hint: Java's Scanner.hasNext() method is helpful for this problem.
Input Format
Read some unknown <span class="MathJax" data-mathml="n" id="MathJax-Element-3-Frame" role="presentation" style="border: 0px; direction: ltr; display: inline; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; position: relative; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;" tabindex="0">n lines of input from stdin(System.in) until you reach EOF; each line of input contains 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:
k This is the line read as input for line number 'k'.
Sample Input
Hello world
I am a file
Read me until end-of-file.
Sample Output
1 Hello world
2 I am a file
3 Read me until end-of-file.solution:
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 lineNumber= 1;
while(scan.hasNext())
{
String readLine = scan.nextLine();
System.out.println(lineNumber + " "+ readLine);
lineNumber++;
}
}
}