方法多了去了,定义个int a,给个while循环,循环的判断条件是 a不符合的条件 (意思是只要a不符合条件,就无限制的执行循环体里的内容)
然后循环体里,你给个控制台输入就好。
或者用goto
输入的数字如果符合规则,跳到符合规则后执行的,如果不符合,跳到执行输入前。
这是思路,具体那里不会的,再问吧
import java.util.Arrays;
import java.util.Scanner;
public class Hello {
public static void main(String[] args) {
//1.
//2.
Scanner s = new Scanner(System.in);
System.out.println("请输入评委数目:");
int judgeNumber = s.nextInt();
double score[] = new double[judgeNumber];
int judgesId[] = new int[judgeNumber];
for(int i = 0; ijudgesId[i] = i+1;
}
for(int i =0;iSystem.out.println("请"+(i+1)+"号评委打分,请输入0-10以内的数:");
double temp = s.nextDouble();
if(temp>0 && temp<10){
score[i] = temp;
}else{
while(true){
System.out.println("不符合打分规范,请重新输入:");
score[i] = s.nextDouble();
if(score[i]>0 && score[i]<10){
break;
}
}
}
}
double max = score[0];
int maxScore = 0;
for(int i = 0;iif(max max = score[i];
maxScore = i;
}else{
continue;
}
}
System.out.println("去掉一个最高分,第"+(maxScore+1)+"位评委打分:"+max);
double min = score[0];
int minScore = 0;
for(int i = 0;iif(score[i] min=score[i];
minScore = i;
}else{
continue;
}
}
System.out.println("去掉一个最低分,第"+(minScore+1)+"位评委打分:"+min);
//Arrays.sort(score);//排序数组
//score = Arrays.copyOfRange(score, 1, score.length-1);//去值后数组
int sum = 0;
for(int i = 0;iif(i == maxScore || i == minScore){
continue;
}else{
sum += score[i];
}
}
System.out.println("平均得分:"+sum/(score.length-2));
}
}