Java 必需变量,找到值
在if语句中,将作为意外类型返回–必需:变量找到:值。我试了一下,但显然不起作用Java 必需变量,找到值,java,Java,在if语句中,将作为意外类型返回–必需:变量找到:值。我试了一下,但显然不起作用 public class Array { private College[] coll; public Array(College[] coll){ this.coll = coll; } public String changeTheValue(String name,int number){ String result= new String(
public class Array
{
private College[] coll;
public Array(College[] coll){
this.coll = coll;
}
public String changeTheValue(String name,int number){
String result= new String();
for(int i = 0 ; i < this.coll.length-1;i++){
if(this.coll[i].getName() == name){
this.coll[i].getNumber() = number;
res += "Successfully changed the value of name "+this.coll[i].getName()+" "+this.coll[i].getNumber()+"\n";
}
else {
res +=this.coll[i].getName()+" not found.";
}
}
return result;
}
}
公共类数组
{
私立学院[]学院;
公共数组(College[]coll){
this.coll=coll;
}
公共字符串更改值(字符串名称、整数){
字符串结果=新字符串();
for(int i=0;i
this.maha[i].getNilai()
正在返回一个值,您试图将该值设置为该值,因此会出现该错误
您需要一个setter函数
像
在问题中始终以文本形式提供答案。请记住,本网站的目的是提供高质量问题和答案的存储库。一个标题问题,然后只是一个屏幕截图的链接,这不是高质量的问题。可能是重复的是,你是对的@Andreas。图中是尼莱:P
this.maha[i].setNilai(number);