Student.javaimport java.io.*;
import java.util.*;
public class Student{
public static void main( String[] args){
int n;
Scanner in = new Scanner(System.in);
System.out.println("请输入学生的个数:");
n = in.nextInt();
String[] stu=new String[n];
int[] score = new int[n];
for(int i=0;i
stu[i] = in.next();
score[i]= in.nextInt();
}
int first,second,first_i,second_i;
first = score[0];
second= score[0];
first_i= 0;
second_i=0;
for(int i=1;i
if(score[i] >second){
second = score[i];
second_i = i;
if(second > first){
int t = second;
second = first;
first = t;
t = second_i;
second_i = first_i;
first_i = t;
}
}
}
System.out.println("最高分学生:" + stu[first_i]+"t分数:"+first);
System.out.println("第二高分学生:" + stu[second_i]+"t分数:"+second);
}
}
运行结果:
java Student
请输入学生的个数:
5
张三 1
李四 2
王五 3
赵八 3
孙九 5
最高分学生:孙九 分数:5
第二高分学生:王五 分数:3
温馨提示:答案为网友推荐,仅供参考
本文发布于:2024-01-31 22:42:59,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170671218131915.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |