且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java Scanner连续用户输入?

更新时间:2023-12-04 17:54:04

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);
        }

    }
}