Java End-of-file
If You Want Explanation Check Video:
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.
Code:
import java.io.*;import java.util.*;
public class Solution {
public static void main(String[] args) { int i = 1; Scanner scn = new Scanner(System.in); String s; while(scn.hasNext()){ s = scn.nextLine(); System.out.println(i+" "+s); i++; } }}
Comments
Post a Comment