mport java.util.Scanner;
public class DoWhile2 {
public static void main(String[] args) {
int min=0;//最小值
int max=0;//最大值
int num=0;
Scanner input=new Scanner(System.in);
System.out.print("请输入一个整数(输入0结束):");
boolean isRight;
do{
num=input.nextInt();
switch(num){
case 0:
isRight=true;
break;
default:
isRight=false;
System.out.print("请输入一个整数(输入0结束):");
/*if(num==0){
max=min=num;
}*/
if(num>max){ //确保min<=num<=max
max=num;
}
if(num<min){
min=num;
}
break;
}
}while(isRight==false);
System.out.println("最大值:"+max+"最小值:"+min);
}
}
时间: 2024-12-15 00:30:21