Fairly new to learning interview questions and I saw this one and gave it a shot. I would very much appreciate some constructive criticism of how I went about it and what you would tell me if you were the interviewer and watched me implement it this way.
public class FizzBuzz {
public static void main(String[] args) {
// Go from 1 to 100
for (int i = 1; i <= 100; i++) {
String result = "";
if (i % 3 == 0) { // If divisible by 3
result += "Fizz";
}
if (i % 5 == 0) { // If divisible by 5
result += "Buzz";
}
// If it was divisible by either 3 or 5 (or both), print Fizz, Buzz, or FizzBuzz accordingly.
if (i % 3 == 0 || i % 5 == 0) {
System.out.println(result);
} else { // Or else just print the integer
System.out.println(i);
}
}
}