Read input line by line

前端 未结 3 1402
面向向阳花
面向向阳花 2021-02-18 22:59

How do I read input line by line in Java? I searched and so far I have this:

import java.util.Scanner;

public class MatrixReader {
    public static void main(S         


        
3条回答
  •  心在旅途
    2021-02-18 23:39

    The previously posted suggestions have typo (hasNextLine spelling) and new line printing (println needed each line) issues. Below is the corrected version --

    import java.util.Scanner;
    
    public class XXXX {
        public static void main(String[] args) {
            Scanner input = new Scanner(System.in);
            while (input.hasNextLine()){
                System.out.println(input.nextLine());
            }
        }
    }
    

提交回复
热议问题