+ 1
boolean with setter & getter
Hello, maybe you can help? My Output should be at the number 1 = true, but it gives me a false back. You know why? public void setFinal(boolean[] finalStates) { // TODO Auto-generated method stub boolean[] result = new boolean[3]; for(int i =0; i <3; i++) { if(i==1) { result[i] = true; } else { result[i] = false; } } } public boolean[] getFinal() { // TODO Auto-generated method stub boolean[] result = new boolean[3]; setFinal(result); return result; My Output is always: false false false Correct output should be: false true false
2 Antworten
+ 1
You give the array result as parameter but creating a new one and changes its values and then returns it without initialization to the first result variable.
So just don't create the new variable in the function setFinal but use the parameter finalStates
0
Thank you so much.