首页 > 开发 > JAVA > 正文

M:\java>javac Stu.java Stu.java:10: 需要 <标识符>

2017-09-07 09:24:53  来源:网友分享
class Student{
    double number;
	string name;
	string sex;
	string department;
	string professional;
	string fond;
	Student(){}
	Student(double nu,string n,string s, string d, string p,string f);
	    number=nu;
		  name=n;
		  sex=s;
		  department=d;
		  professional=p;
		  fond=f;
        
    public void setNumber(double nu){
	     Number=nu;
	   }
	     double getNumber(){
	     return Numeber;
	  }
	public void setName(string n){
	     Name=n;
	   }
        string getName(){
         return Name;
      }  		 
	public void setSex(string s){
         Sex=s;
         }
         string getSex(){
            return Sex;
              }
	public void setDepartment(string d){
             Department=d;
       }
        string getDepartment(){
             return Department;
	  }
	public void setProfessional(string p){
	         Professional=p;
			 }
		string getProfessional(){
		     return Professional;
			 }
	public void setFond(string f){
	         Fond=f;
		 }
			 string getFond(){
			  return Fond;
			  }
	}
 public class  Stu{
     public static void main(string args[]){
	     Student message=new Student();
		   message.setNumber(200005064121.0f);
		   message.setName("xxx");
		   message.setSex("男");
		   message.setDepartment("xxx学院");
		   message.setProfessional("xxx");
		   message.setFond("网络信息技术");
	System.out.prdoubleln("学号"+getNumber);
	System.out.prdoubleln("姓名"+getName);
	System.out.prdoubleln("姓别"+getSex);
	System.out.prdoubleln("系别"+getDepartment);
	System.out.prdoubleln("专业"+getProfessional);
	System.out.prdoubleln("爱好"+getFond);
	System.out.prdoubleln("JAVAxxxx");
	   }

编译后出现

M:\java>javac Stu.java
Stu.java:10: 需要 <标识符>
            number=nu;
                  ^
Stu.java:11: 需要 <标识符>
                  name=n;
                      ^
Stu.java:12: 需要 <标识符>
                  sex=s;
                     ^
Stu.java:13: 需要 <标识符>
                  department=d;
                            ^
Stu.java:14: 需要 <标识符>
                  professional=p;
                              ^
Stu.java:15: 需要 <标识符>
                  fond=f;
                      ^

帮帮忙

解决方案

改成这样:

Student(double nu,string n,string s, string d, string p,string f)
{
    number=nu;
    name=n;
    sex=s;
    department=d;
    professional=p;
    fond=f;
}

注意:初学者提问,贴代码的时候一定要注意代码风格。缩进对齐、变量命名、必要的注释、空格空行都要注意。