调试说是输入空字符串,请问怎样修改,感谢!!!
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;
}
}