
Problem
Solution
Submissions
FizzBuzz Implementation
Certification: Basic Level
Accuracy: 57.14%
Submissions: 35
Points: 5
Write a Java program to implement the classic FizzBuzz problem. For numbers from 1 to n, print "Fizz" for multiples of 3, "Buzz" for multiples of 5, and "FizzBuzz" for multiples of both.
Example 1
- Input: n = 15
- Output:
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz - Explanation:
- Multiples of 3 → "Fizz"
- Multiples of 5 → "Buzz"
- Multiples of both → "FizzBuzz"
Example 2
- Input: n = 8
- Output:
1
2
Fizz
4
Buzz
Fizz
7
8 - Explanation:
- Apply same logic for smaller range
Constraints
- 1 ≤ n ≤ 10^5
- Time Complexity: O(n)
- Space Complexity: O(1)
Editorial
My Submissions
All Solutions
Lang | Status | Date | Code |
---|---|---|---|
You do not have any submissions for this problem. |
User | Lang | Status | Date | Code |
---|---|---|---|---|
No submissions found. |
Solution Hints
- Loop through each number from 1 to n
- Check if the number is divisible by both 3 and 5
- If not, check if the number is divisible by 3
- If not, check if the number is divisible by 5
- If none of the above conditions are met, print the number itself