public class Test2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = 0;
while (true) {
System.out.println("input number:");
x = sc.nextInt();
System.out.println(x);
}
}
}
把close那句去掉就行了,然后可以把变量的定义放在while外面,减少内存消耗~虽然耗得不多