一元运算符'+'的坏操作数类型字符串

时间:2013-05-02 13:09:12

标签: java netbeans

我目前正在处理一个包含多个学生对象的模块类,并且遇到了以下问题 -

一元运算符'+'的错误操作数类型字符串

我将不胜感激,我的代码如下。

public class Module {
private String moduleTitle;
int percentageCoursework;
int percentageExam;
private Student studentsList[] = new Student[3];

public Module (String moduleTitle, int percentageCoursework, int percentageExam,String     studentOne, String studentTwo, String studentThree, String studentsTitles[])
{        
this.moduleTitle = moduleTitle;
this.percentageCoursework = percentageCoursework;
this.percentageExam = percentageExam;
this.studentsList[0].name = studentOne;
this.studentsList[1].name = studentTwo;
this.studentsList[2].name = studentThree;

}
            public void ShowDetails()
{
    System.out.println("moduleTitle : " + moduleTitle + 
            "\n percentageCoursework : " + percentageCoursework + 
            "\n percentageExam : " + percentageExam + 
            +studentsList[0].name+studentsList[1].name+studentsList[2].name);

    }
} 

2 个答案:

答案 0 :(得分:10)

    "\n percentageExam : " + percentageExam + 
    +studentsList[0].name+studentsList[1].name+studentsList[2].name);
//  ^
//  ^ look! oh noes!

在最后一行的开头有一个额外的+

答案 1 :(得分:0)

percentageExam + +studentsList[0].name+studentsList[1].name

             //  ^^  Two "+" side by side.