How to read input with multiple lines in Java

后端 未结 10 1170
名媛妹妹
名媛妹妹 2020-12-05 02:48

Our professor is making us do some basic programming with Java, he gave a website and everything to register and submit our questions, for today I need to do this one exampl

10条回答
  •  甜味超标
    2020-12-05 03:30

    A lot of student exercises use Scanner because it has a variety of methods to parse numbers. I usually just start with an idiomatic line-oriented filter:

    import java.io.*;
    
    public class FilterLine {
    
        public static void main(String[] args) throws IOException {
            BufferedReader in = new BufferedReader(
                new InputStreamReader(System.in));
            String s;
    
            while ((s = in.readLine()) != null) {
                System.out.println(s);
            }
        }
    }
    

提交回复
热议问题