答案家

 找回密码
 立即注册
查看: 1386|回复: 0

java实现找出两个分数最高的学生程序源码

[复制链接]

1万

主题

1万

帖子

80万

积分

校长

Rank: 9Rank: 9Rank: 9

积分
809292
发表于 2016-12-24 16:06:33 | 显示全部楼层 |阅读模式
package nameyu;
import java.util.Scanner;
public class Test {
    /**
     * @param args
     */
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        System.out.print("Enter student numbers:");
        int number=input.nextInt();
        String []student=new String[number];
        double []score=new double[number];
        double max1=0,max2=0;
        int index1=0,index2=0;
        for(int i=0;i<number;i++){
             System.out.print("Enter student name:");
             student=input.next();
             System.out.print("Enter student score:");
             score=input.nextDouble();
            if(score>max1&&score>max2){
                max1=score;
                index1=i;
            }else if(score<max1&&score>max2){
                max2=score;
                index2=i;
            }
        }
        System.out.println("The max score name is "+student[index1]+" score is "+score[index1]+" The second score name is "+student[index2]+" score is "+score[index2]);
            }
            }

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

CopyRight(c)2016 www.daanjia.com All Rights Reserved. 本站部份资源由网友发布上传提供,如果侵犯了您的版权,请来信告知,我们将在5个工作日内处理。
快速回复 返回顶部 返回列表