I want to input a paragraph (multiple lines) at the same time (not one line by one line) in Java. I want to add "the line number is :" to each line I input in command prompt, and exit it when the input is null. The code below is my attempt.
I tried to research on Internet, but I am still confused with Scanner and BufferedReader.
How do I adjust my program?
import java.io.*;
public class Word {
public static void main(String[] args) throws IOException{
InputStreamReader is = new InputStreamReader(System.in);
BufferedReader input=new BufferedReader(is);
String s=input.readLine();
int lineNum=1;
while(s!=null&&s.length()>0) {
System.out.println("Line number "+lineNum+" : "+s);
lineNum++;
}
}
}