Java Scanner Continuous User input?

前端 未结 3 1440
半阙折子戏
半阙折子戏 2021-01-03 05:00

For java practice, i am trying to create a program that reads integers from the keyboard until a negative one is entered.

and it prints the maximum and minimum of th

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-03 06:00

    import java.util.Scanner;
    
    public class ABC {
    public static void main(String []args) {
            int num;
            Scanner scanner = new Scanner(System.in);
            System.out.println("Feed me with numbers!");
    
            while((num = scanner.nextInt()) > 0) {
                System.out.println("Keep Going!");
            }
    
            {
                System.out.println("Number is negative! System Shutdown!");
                System.exit(1);
            }
    
        }
    }
    

提交回复
热议问题