double english=60.5;
double math=70.0;
double chinese=80.0;
double course=Math.max(english, math);
double top=Math.max(course, chinese);
System.out.println("成绩最高的科目:"+top);
运行结果: 80.0我想将运行结果  是成绩最高的那一门所对应的科目,即输出Chinese,而不是最高科目的分数80.0,该怎么办?

解决方案 »

  1.   

    用map,key为分数,value为chinese之类的字符串,
    System.out.println("成绩最高的科目:"+map.get(top)); 
      

  2.   

    public class Test4{
    public static void main(String[] args){
    double[] score={60.5,70.0,80.0,74,65};
    String[] course={"English","Math","Chinese","Music","Drawing"};
    int maxIndex=max(score);
    System.out.println("最高分是:"+course[maxIndex]+" : "+score[maxIndex]);
    }
    public static int max(double[] score){
    int maxIndex=0;
    for(int i=1;i<score.length;i++){
    if(score[i]>score[maxIndex]){
    maxIndex=i;
    }
    }
    return maxIndex;
    }
    }
    F:\java>java Test4
    最高分是:Chinese : 80.0
      

  3.   

    半级键盘修理工说的极是:
    public class t0{
    private static int max( double f[]){
    double MaxValue = f[0];
    int max = 0;
    for (int i=1;i<f.length; i++)
    if (MaxValue < f[i]){
    MaxValue = f[i];
    max = i;
    }
    return max; 
    }
    public static void main(String args[]) {
    String name[]= {"english","math","chinese"};
    double score[] = {60.5,70.0,80.0};
    System.out.println("成绩最高的科目:"+ name[max(score)]);; 
    }
    }
      

  4.   

    只是,她只要最大值,TreeMap是对全部的数据排序,有点浪费。