标题:从键盘输入三个学生的五门成绩
取消只看楼主
黄金九六
Rank: 2
等 级:论坛游民
帖 子:10
专家分:14
注 册:2016-7-14
结帖率:66.67%
已结贴  问题点数:20 回复次数:2 
从键盘输入三个学生的五门成绩
package stu;

import java.util.Scanner;

public class student {
    public static void main(String[] args){
        //从键盘输入三个学生的五门成绩
        St s[] = new St[3];
        s[0].info(0);
        s[1].info(1);
        s[2].info(2);
    }
}

class St{
    //学生五门课,学号和成绩
    String Name;
    public String getName(String name) {
          return Name = name;
         }
   
    int Num;
    public int getNum(int num) {
          return Num = num;
         }
   
    double Chinese;
    public double getChinese(double chinese) {
          return Chinese = chinese;
         }
   
    double Math;
    public double getMath(double math) {
          return Math = math;
         }
    double English;
    public double getEnglish(double english) {
          return English = english;
         }
   
    double Phyics;
    public double getPhyics(double phyics) {
          return Phyics = phyics;
         }
   
    double Chemistry;
    public double getChemistry(double chemistry) {
          return Chemistry = chemistry;
         }
   
    public void info(int i){
        St s = new St();
            System.out.println("请输入第" + i+1 +"个学生的信息");
                //输入学生的名字
            System.out.println("姓名:");
            Scanner n = new Scanner(System.in);
            String name = n.nextLine();
            s.Name = s.getName(name);
            //输入学生的学号
            System.out.println("学号:");
            Scanner b = new Scanner(System.in);
            int num = b.nextInt();
            s.Num = s.getNum(num);
            //输入学生的语文成绩
            System.out.println("Chinese:");
            Scanner c = new Scanner(System.in);
            double chinese = c.nextInt();
            s.Chinese = s.getChinese(chinese);
            //输入学生的数学成绩
            System.out.println("Math:");
            Scanner d = new Scanner(System.in);
            double math = d.nextInt();
            s.Math = s.getMath(math);
            //输入学生的英语成绩
            System.out.println("English:");
            Scanner e = new Scanner(System.in);
            double english = e.nextInt();
            s.English = s.getEnglish(english);
            //输入学生的物理成绩
            System.out.println("Phyics:");
            Scanner f = new Scanner(System.in);
            double phyics = f.nextInt();
            s.Phyics = s.getPhyics(phyics);
            //输入学生的化学成绩
            System.out.println("Chemistry:");
            Scanner g = new Scanner(System.in);
            double chemistry = g.nextInt();
            s.Chemistry = s.getChemistry(chemistry);
            }
}
为什么不能运行?求大神指点。
搜索更多相关主题的帖子: package public return import 键盘 
2017-03-25 11:27
黄金九六
Rank: 2
等 级:论坛游民
帖 子:10
专家分:14
注 册:2016-7-14
得分:0 
回复 3楼 王小翔
兄弟,我问了一下老师,他说是因为数组对象和普通对象的区别,但我还是不太清楚其中的具体情况。如果你搞清楚了记得顺便跟我说一声。
2017-03-25 21:51
黄金九六
Rank: 2
等 级:论坛游民
帖 子:10
专家分:14
注 册:2016-7-14
得分:0 
回复 3楼 王小翔
兄弟,我明白了,在用数组之前还要实例化一下数组元素。如在用  s[0].info(i)之前还要加一句  s[0] = new St();这样就可以了!!
2017-03-25 22:17



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




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

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