标题:调试说是输入空字符串,请问怎样修改,感谢!!!
取消只看楼主
air5116
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2014-11-1
结帖率:40%
 问题点数:0 回复次数:1 
调试说是输入空字符串,请问怎样修改,感谢!!!
import java.util.Scanner;

public class Demo {
    Stu stu[] = new Stu[3];

    public void inputjavaGrade() {

        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < stu.length; i++) {
            System.out.println("请输入第" + (i + 1) + "学生的学号:");
            stu[i].setNumber(sc.nextLine());
            System.out.println("请输入第" + (i + 1) + "学生的姓名:");
            stu[i].setName(sc.nextLine());
            System.out.println("请输入第" + (i + 1) + "学生的java成绩:");
            stu[i].setJavaGrade(sc.nextFloat());
        }

    }

    public void vaGrade() {
        float vaGrade = 0;
        float allGrade = 0;
        for (int i = 0; i < stu.length; i++) {
            allGrade += stu[i].getJavaGrade();
            vaGrade = allGrade / stu.length;
            System.out.println("学生的Java总成绩为" + allGrade);
            System.out.println("第" + (i + 1) + "学生的平均成绩为" + vaGrade);
        }
    }

    public void maxGrade() {
        float max = 0;
        int i = 0;
        while (i < stu.length) {
            if (stu[i].getJavaGrade() > max) {
                max = stu[i].getJavaGrade();
            }
            i++;
        }
        System.out.println("最高成绩的同学学号为" + stu[i].getNumber() + "成绩是" + max);
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Demo demo = new Demo();
        demo.inputjavaGrade();
        demo.vaGrade();
        demo.maxGrade();
    }

}

class Stu {
    private String number;
    private String name;
    private float javaGrade;

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public float getJavaGrade() {
        return javaGrade;
    }

    public void setJavaGrade(float javaGrade) {
        this.javaGrade = javaGrade;
    }

}
搜索更多相关主题的帖子: public import 字符串 姓名 
2015-06-14 14:08
air5116
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2014-11-1
得分:0 
真的非常感谢,之前代码真的很多错误
2015-06-14 17:30



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-446582-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.164255 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved