How can I repeatedly read user input using Scanner java

前端 未结 3 1040
一个人的身影
一个人的身影 2021-01-24 13:08

I am trying to create a simple menu for my program that reads user input. Here\'s the code:

public void menu() {
        String command;

        System.out.prin         


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-24 13:16

    You can use

    InputStreamReader str= new InputStreamReader (System.in);
    BufferedReader uinp= new BufferedReader (str);
    String val;
    val= uinp.readLine();
    while (!".".equals(val)) {
    //do your stuff
    //..and after done, read the next line of the user input.
    val= uinp.readLine();
    }
    

提交回复
热议问题