FizzBuzz challenge prob

The FizzBuzz challenge, I’m having trouble removing the numbers. I can get Fizz, Buzz and FizzBuzz when I run the code but the numbers aren’t removed from the output. Can anyone at least point me in the right direction?

Here is my code:

class FizzBuzz{
public static void main(Stringargs){
for (int i = 1; i <= 100; i++){
if (i % 3 == 0 && i % 5 == 0){
System.out.println(“FizzBuzz”);
}

  else (i % 3 == 0){
    System.out.println("Fizz");
  }

  else (i % 5 == 0){
    System.out.println("Buzz");
  } 
 System.out.println(i);
 
} 

}
}

Any help would be appreciated. I’ve been stumped on this off and on for this past week.

Thanks,

Hey there, welcome to the forums.

Unless I’m missing something, I don’t see how this is working?

Shouldn’t your conditional statements look like this:

if (condition) {
  do something
} else if (other condition) {
  do something else
} else {
  do something else
}

What do you mean?

Isn’t this the desired output:

Summary

1
2
Fizz
3
4
Buzz
5
Fizz
6
7
8
Fizz
9
Buzz
10
11
Fizz
12
13
14
FizzBuzz
15
16
17
Fizz
18
19
Buzz
20
Fizz
21
22
23
Fizz
24
Buzz
25
26
Fizz
27
28
29
FizzBuzz
30
31
32
Fizz
33
34
Buzz
35
Fizz
36
37
38
Fizz
39
Buzz
40
41
Fizz
42
43
44
FizzBuzz
45
46
47
Fizz
48
49
Buzz
50
Fizz
51
52
53
Fizz
54
Buzz
55
56
Fizz
57
58
59
FizzBuzz
60
61
62
Fizz
63
64
Buzz
65
Fizz
66
67
68
Fizz
69
Buzz
70
71
Fizz
72
73
74
FizzBuzz
75
76
77
Fizz
78
79
Buzz
80
Fizz
81
82
83
Fizz
84
Buzz
85
86
Fizz
87
88
89
FizzBuzz
90
91
92
Fizz
93
94
Buzz
95
Fizz
96
97
98
Fizz
99
Buzz
100

?

1 Like

I am not very familiar with Java but, I think this ^ is the root behind your problem. I mean, you are printing ‘i’ so ‘i’ will always be visible.

But, I think you want something like this:

if (/*divisible by 15*/){}
else if (/*divisible by 5*/){}
else if(/*divisible by 3*/){}
else{/*Print: i*/}

PS: Check your if-else if syntax too.