FizzBuzz prints Fizz and also the number please help!

class FizzBuzz {



  public static void main(String[] args) {

    for (int i = 1; i <= 100; i++){

      if (i % 3 == 0 && i % 5 == 0) {

        System.out.println("FizzBuzz");

      }

      else if (i % 3 == 0) {

        System.out.println("Fizz");

      }

      else if (i % 5 == 0) {

        System.out.println("Buzz");

      }

      else {

        System.out.println(i);

      }

    }

    }

Hey above is my code but it will print 1,2,3,Fizz, 4, 5, Buzz and I can’t figure out why.

Please help!

Hello, @giga7526047337, and welcome to the forums.

Your code works as expected when I run it (after adding the missing closing brace for the class).

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.