代码如下:
import java.util.Scanner;
public class App64 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;
boolean exit = false;
while (!exit) {
System.out.print("请输入1~10之间的数(输入0结束):");
int number = scanner.nextInt();
if (number >= 1 && number <= 10) {
if (number > max) {
max = number;
}
if (number < min) {
min = number;
}
} else if (number == 0) {
exit = true;
}
}
System.out.println("最大值:" + max);
System.out.println("最小值:" + min);
}
}
运行结果: