I'm doing a FizzBuzz test, and I notice the variable set in one of if statement is not working in another if condition. In below method, the input int number = 1, also getPrev() = 1, thus the expected output should = 1Bingo, however the real output is 1. If I change condition if(output == getPrev()) to if("1" == getPrev()), then the output is correct. Why the variable set in previous if statement is not working in next if condition?
public String evaluate(int number) {
String output = "";
if (number % 15 == 0) {
output = "FizzBuzz";
//return output;
}
else if (number % 3 == 0) {
output ="Fizz";
//return output;
}
else if (number % 5 == 0) {
output = "Buzz";
//return output;
}
else if (number % 3 != 0 && number % 5 != 0) {
output = String.valueOf(number);
//return output;
}
if(output == getPrev()) {
output += "Bingo";
}
return output;
}