又来请教了

小神zuo 2009-08-08 10:01:55
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,该怎么办?
...全文
101 9 打赏 收藏 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
bigbug9002 2009-08-08
  • 打赏
  • 举报
回复
只是,她只要最大值,TreeMap是对全部的数据排序,有点浪费。
bigbug9002 2009-08-08
  • 打赏
  • 举报
回复
用Map,就用TreeMap.
tongj2me 2009-08-08
  • 打赏
  • 举报
回复
半级键盘修理工说的极是:
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)]);;
}
}
小神zuo 2009-08-08
  • 打赏
  • 举报
回复
有待学习。。。
bigbug9002 2009-08-08
  • 打赏
  • 举报
回复
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
ldg_2 2009-08-08
  • 打赏
  • 举报
回复
用map,key为分数,value为chinese之类的字符串,
System.out.println("成绩最高的科目:"+map.get(top));
koskoswh12 2009-08-08
  • 打赏
  • 举报
回复
楼上正解~~
sinpinle 2009-08-08
  • 打赏
  • 举报
回复
用map不就可以了么
bigbug9002 2009-08-08
  • 打赏
  • 举报
回复
用两个数组,一个放课课程的名字,一个放对应成绩.
求最高分,自己写算法求,求的过程只记录最大数的下标.
一个下标对应两个数组,一个是成绩,一个是课程.

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧