寻找最大数和第二大数
2015-10-15 15:03
267 查看
import 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
;
int[] score = new int
;
for(int i=0;i<n;i++){
stu[i] = in.next();
score[i]= in.nextInt();
}
int first,second,first_i,second_i;
if(score[0]>=score[1]) {
first=score[0];
first_i=0;
second=score[1];
second_i=1;
}
else {
first=score[1];
first_i=1;
second=score[0];
second_i=0;
}
for(int i=2;i<n;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);
}
}
相关文章推荐
- Android Fragment小试一下
- MySQL创建用户、赋予权限
- MongoDB一次性能问题处理
- jQuery DataTables
- UML画用例图
- 安卓ListView使用错误解决
- RBAC php
- Android Fragment小试一下
- 限制UITextField只可以输入数字
- jQuery的选择器中的通配符[id^='code']
- maven插件
- PG常用管理命令
- struts下载
- i2c驱动架构 davinc dm368 i2c驱动分析
- Android 使用android-support-multidex解决Dex超出方法数的限制问题,让你的应用不再爆棚
- 有关一些汉字编码
- ADB 无法识别问题
- android开机自启动service
- TabLayout的使用
- Android的Dialog和PopupWindow的使用