import java.util.*;
public class StudentInfo
{
private String stuName;
private int stuAge;
private String stuSex;
private double stuScore;
public StudentInfo(String stuName, int stuAge,String stuSex,double stuScore)
{
 this.stuName=stuName;
 this.stuAge=stuAge;
 this.stuSex=stuSex;
 this.stuScore=stuScore;
}
public void showStuInfo(StudentInfo sti)
{
Scanner sc=new Scanner(System.in);
System.out.println("请输入信息");

System.out.println("请输入姓名:");
stuName=sc.next();
System.out.println("请输入年龄:");
stuAge=sc.nextInt();
System.out.println("请输入性别:");
stuSex=sc.next();
  System.out.println("请输入成绩:");
stuScore=sc.nextInt();
System.out.println(stuName+"的信息如下:");
System.out.println("=================================");
System.out.println("姓名\t年龄\t性别\t成绩");
System.out.println(stuName+"\t"+stuAge+"\t"+stuSex+"\t"+stuScore);
 System.out.println("=================================");
   
}
public static void main(String []args)
{
   showStuInfo();

}
}
 哪位高手帮我看哈呀 这个编译报错, 是不是使用了构造方法就只能传值而不能动态输入呀? 刚接触Java各位高手不要笑话哈!!软件初学者真心求助 

解决方案 »

  1.   

    main函数是静态方法,只能调用静态方法和访问静态变量
      

  2.   

    把public void showStuInfo(StudentInfo sti)
    {void去掉  直接用调用构造方法的方式 
    或者 在main方法里面:StudentInfo sut =  new  StudentInfo();
    然后 sut.showStuInfo();
    或者将void 改为static你的代码除了这个问题外  还有 你的方法里面需要传递一个StudentInfo 实例  你调用的时候 showStuInfo();这个方法 根本找不到