class Adder{
int value;
int var1;
public Adder(int x){
this.var1 = x;
}
public int add(){
value += var1;
return getValue();
}
public int getValue(){
return value;
}
}
class Solution {
public int solution(int[] arr) {
Adder adder = new Adder(0);
for(int x : arr){
adder.add(x);
}
int answer = adder.getValue();
return answer;
}
}
It's homework, but I've been doing this and that for 3 hours, but I really don't know what the problem is and how to return it.
java method class
Value value is not initialized in the Adder class
© 2024 OneMinuteCode. All rights reserved.