How to read input with multiple lines in Java

后端 未结 10 1175
名媛妹妹
名媛妹妹 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:47

    This is good for taking multiple line input

    import java.util.Scanner;
    public class JavaApp {
        public static void main(String[] args){
            Scanner scanner = new Scanner(System.in);
            String line;
            while(true){
                line = scanner.nextLine();
                System.out.println(line);
                if(line.equals("")){
                    break;
                }
            }
        }  
    }
    

提交回复
热议问题