首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

简略程序求解

2013-11-13 
简单程序求解!class Student2{private String nameprivate int ageprivate float englishprivate float

简单程序求解!
class Student2{
private String name;
private int age;
private float english;
private float computer;
private float math;
public Student2(){}
public Student2(String n,int a,float e,float c,float m){
this.setName(n);
this.setAge(a);
this.setEnglish(e);
this.setComputer(c);
this.setMath(m);
}
public float sum(){
return english+computer+math;
}
public float avg(){
return this.sum()/3;
}
public float max(){
float max=computer>math?computer:math;
max=max>english?max:english;
return max;
}
public float min(){
float min=computer<math?computer:math;
min=min<english?min:english;
return min;
}
public String getInfo(){
return "student information:\n"+
"\t|- name is"+this.getName()+"\n"+
"\t|- age is"+this.getAge()+"\n"+
"\t|- math is"+this.getMath()+"\n"+
"\t|- english is"+this.getEnglish()+"\n"+
"\t|- computer is"+this.getComputer();
}
public void setName(String n){
name = n;
}
public void setAge(int a){
age = a;
}
public void setEnglish(float e){
english = e;
}
public void setComputer(float c){
computer = c;
}
public void setMath(float m){
math = m;
}
public String getName(){
return name;
}
public int getAge(){
return age;
}
public float getEnglish(){
return english;
}
public float getComputer(){
return computer;
}
public float getMath(){
return math;
}
}
public class Demo12 {
    public static void main(String args[]){
    Student2 stu = new Student2("zhangsan",30,89.0f,91.0f,87.0f);
    System.out.println("the sum"+stu.sum());
    System.out.println("the avg"+stu.avg());
    System.out.println("the max"+stu.max());
    System.out.println("the min"+stu.min());
    System.out.println(stu.getInfo());
    }
}
简略程序求解简略程序求解
各位大神,帮忙看看究竟是哪里出错了。好像环境变量应该没问题,其他程序都可以正常运行~
[解决办法]
public class Demo12 {
    public static void main(String args[]){
    Student2 stu = new Student2("zhangsan",30,89.0f,91.0f,87.0f);
    System.out.println("the sum"+stu.sum());
    System.out.println("the avg"+stu.avg());
    System.out.println("the max"+stu.max());
    System.out.println("the min"+stu.min());
    System.out.println(stu.getInfo());
    }
把public 删掉 
class Demo12 {
    public static void main(String args[]){
    Student2 stu = new Student2("zhangsan",30,89.0f,91.0f,87.0f);
    System.out.println("the sum"+stu.sum());
    System.out.println("the avg"+stu.avg());
    System.out.println("the max"+stu.max());
    System.out.println("the min"+stu.min());
    System.out.println(stu.getInfo());
    }
[解决办法]
在我这里没有错,请检查你的运行环境
[解决办法]

引用:
Quote: 引用:

public class Demo12 {
    public static void main(String args[]){
    Student2 stu = new Student2("zhangsan",30,89.0f,91.0f,87.0f);
    System.out.println("the sum"+stu.sum());
    System.out.println("the avg"+stu.avg());
    System.out.println("the max"+stu.max());
    System.out.println("the min"+stu.min());
    System.out.println(stu.getInfo());
    }
把public 删掉 
class Demo12 {
    public static void main(String args[]){
    Student2 stu = new Student2("zhangsan",30,89.0f,91.0f,87.0f);
    System.out.println("the sum"+stu.sum());


    System.out.println("the avg"+stu.avg());
    System.out.println("the max"+stu.max());
    System.out.println("the min"+stu.min());
    System.out.println(stu.getInfo());
    }


还是不能噢。一般都要有一个public的类吧


我这里运行也没问题的,你再试试
[解决办法]
我这里运行也没问题,你重启myeclipse一下看看!

热点排行