Help! FizzBuzz.java doesn't output the result I need

Hello. I have an issue with my code:

class FizzBuzz {

   public static void main(String[] args) {

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

       System.out.println(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);

       }

     }

   }

}

What I want to fix is how the code is printed out. I don’t want it to print the number (the variable i, that is) when it finds a number that is divisible by 3 or 5. I’ve tried to do it in multiple ways, but to no avail.

Thanks in advance!

Take a look at the very first thing your for loop does…

Gosh my attention span is terrible :woman_facepalming: Thanks!

No worries, happens to the best of us!

Happy coding!

Hiya, I’m stuck on FizzBuzz too!

I’m wondering if you can help because I’ll pluck my eyes out but can’t seem to get it…

Below is my code - I cannot get it for the life of me to run. I’ve tried compiling it (fixed the error that I got) and then that’s it, it simply does not run - What am I missing?

Thanks in advance!

public class FizzBuzz {

public static void main(String args) {

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

  if (i % 3 == 0) {
    System.out.println("Fizz");
  } else if (i % 5 == 0) {
    System.out.println("Buzz");
    } else if (i % 3 == 0 && i % 5 ==0) {
      System.out.println("FizzBuzz");
    } else {
      System.out.println(i);
    }
  }

}

}

@system9968476578,

Take a look at the very first line of your for loop. It looks like i starts on a number that is never there…

Hint:

Click here for hint

@el_cocodrilo THANK YOU!
I’ve been looking at it for sooo long and the mistake was in the most obvious place :sweat_smile:

I think it’s time for a break, thank you again :slight_smile:

1 Like