Skip to content

Commit 8117870

Browse files
Merge pull request #265 from Harsh-bartariya/patch-2
End_of_file_solution.java
2 parents 2fc09a6 + 351f576 commit 8117870

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* "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.
2+
The challenge here is to read lines of input until you reach EOF, then number and print all lines of content.
3+
4+
Input Format
5+
Read some unknown lines of input from stdin(System.in) until you reach EOF; each line of input contains a non-empty String.
6+
Output Format
7+
For each line, print the line number, followed by a single space, and then the line content received as input.
8+
9+
Sample Input
10+
11+
Hello world
12+
I am a file
13+
Read me until end-of-file.
14+
15+
Sample Output
16+
1 Hello world
17+
2 I am a file
18+
3 Read me until end-of-file. */
19+
20+
import java.io.*;
21+
import java.util.*;
22+
import java.text.*;
23+
import java.math.*;
24+
import java.util.regex.*; //The Java Regex or Regular Expression is an API to define a pattern for searching or manipulating strings.
25+
26+
public class End_of_file_solution {
27+
28+
public static void main(String[] args) {
29+
Scanner sc=new Scanner(System.in); //creating new scanner object for taking input from user
30+
int i = 0;
31+
while (sc.hasNextLine()) { //checking for the next input token until the loop ends
32+
System.out.printf("%d %s\n",++i,sc.nextLine()); // print the output
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)