2013-05-02 107 views
1

我目前工作的一个模块类与几个学生对象,并已遇到了以下问题 -不好操作数类型字符串元运算符“+”

不好操作数类型字符串元运算符“+”

我将不胜感激任何帮助,我的代码如下。

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); 

    } 
} 

回答

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

有最后一行的开头额外+

+0

非常感谢! – user2343208 2013-05-03 07:56:03

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

      // ^^ Two "+" side by side. 
相关问题