public class Test05 { public static void main(String[] args) { // 6位评委打分{0-100}之间,去掉最高分和最低分,求最后四位平均 Scanner sc = new Scanner(System.in); int arr[] = new int[6]; for (int i = 0; i < 6; i++) { System.out.println("请输入第" + (i + 1) + "评委分数"); arr[i] = sc.nextInt(); while (true) { if (arr[i] >= 0 && arr[i] <= 100) { break; }else{ System.out.println("成绩输入错误,亲重新输入"); } } } Arrays.sort(arr); arr[0] = 0; arr[arr.length - 1] = 0; double max = 0; for (int i = 0; i < arr.length; i++) { System.out.println(arr[i]); max = max + arr[i]; } System.out.println(max / 4); } }
时间: 2023-05-25 13:06:58 浏览: 73
&& arr[i] <= 100) { break; } else { System.out.println("评分输入不合法,请重新输入"); arr[i] = sc.nextInt(); } } } int sum = 0; int max = arr[0]; int min = arr[0]; for (int i = 0; i < 6; i ) { sum += arr[i]; if (arr[i] > max) { max = arr[i]; } if (arr[i] < min) { min = arr[i]; } } int average = (sum - max - min) / 4; System.out.println("最后四位评委的平均分为:" average); } }
相关问题
对下面的代码进行补充,完成抽象类的定义以及相关功能。输出请参考样例。 /* -------------请完善此部分代码-------------- */ Actor { int health = 100; public abstract void showStatus(); public void attack() { } public void setHealth(int health) { this.health = health; } } class Hero extends Actor { /* -------------请完善此部分代码-------------- */ } public class Main { public static void main(String[] args) { /* -------------请完善此部分代码-------------- */ } } 输入格式: 无 输出格式: health:100
/* -------------请完善此部分代码-------------- */
abstract class Actor {
int health = 100;
public abstract void showStatus();
public void attack() {
}
public void setHealth(int health) {
this.health = health;
}
}
class Hero extends Actor {
@Override
public void showStatus() {
System.out.println("health:" + health);
}
}
public class Main {
public static void main(String[] args) {
/* -------------请完善此部分代码-------------- */
Hero hero = new Hero();
hero.showStatus();
}
}
输出:health:100
1.使用字节码对象获取该类中定义公用方法。遍历输出该方法名。package step2; public class ReflectFunc { public static void main(String[] args) { Class<Student> studentClass = Student.class; // ---------------------Begin------------------------ // 根据上方的字节码对象,获取定义的方法并遍历输出 // 获取 Student 类中的getAge方法并将其打印输出 // ---------------------End------------------------ } }
package step2;
import java.lang.reflect.Method;
public class ReflectFunc {
public static void main(String[] args) {
Class<Student> studentClass = Student.class;
// 获取Student类中定义的公共方法
Method[] methods = studentClass.getMethods();
for (Method method : methods) {
System.out.println(method.getName());
}
// 获取指定方法
try {
Method method = studentClass.getMethod("getAge");
System.out.println(method.getName());
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
}
阅读全文