I've been trying to self study on some java code. I came across the famous fizz buzz problem. I have a problem that on the last if statement the output is ok if its not enclosed in curly braces. what the difference of enclosing a statement inside a curly brace vs not? Edit: Output with curly brace (fizz, buzz, fizz, buzz, fizz , buzz ...) Output without curly brace*correct answer (1, 2, fizz, 4, buzz, fizz ...)
boolean checker = true;
for (int i = 0; i < 100; i++){
if (i % 3 == 0){
System.out.print("Fizz");
checker = false;
}
if (i % 5 == 0){
System.out.print("Buzz");
checker = false;
}
if (checker) { // here is the code if curly brace is removed the output is fine
System.out.print(i);
checker = true;
System.out.print(",");
}
}
}