package FizzBuzz;
public class FizzBuzz {
public static void main(String[] args) {
int n = 100;
for(int i =1; i <= n; i++) {
System.out.println(i);
}
if (n % 15 == 0) {
System.out.println("FizzBuzz");
} else if (n % 5 == 0) {
System.out.println("Fizz");
} else if (n % 3 == 0) {
System.out.println("Buzz");
} else {
System.out.println(n);
}
}
}
You have your loop, inside the loop you only print the number
then after/outside the loop, you have a comparison which will print fizz once (100, the last number of the loop is divisible by 5)
1 Like
Please check once here is my output, which printed double number , Please guide
the numbers are always printed by your println()
method call on line 8, is that the desired behavior?
1 Like
system
closed
#5
This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.