答案家

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

java如何实现找出最高分程序?

[复制链接]

1万

主题

1万

帖子

80万

积分

校长

Rank: 9Rank: 9Rank: 9

积分
809292
发表于 2016-12-24 15:59:30 | 显示全部楼层 |阅读模式
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.println("Enter student numbers:");
        int number=input.nextInt();//学生的个数
        String []student=new String[number];//存放学生的姓名
        double []score=new double [number];//存放学生的分数
        double max=0;//最高分
        int index=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>max){
                max=score;
                index=i;
            }
        }
        System.out.println("The max score is "+score[index]+" The name is "+student[index]);
            }
            }

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

本版积分规则

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