Problems - Set 1
Easy
FizzBuzz
A = 5
Return: [1 2 Fizz 4 Buzz]Method 1 - Using loop and if else
ArrayList<String> list = new ArrayList<>();
for (int i = 1; i <= A; i++) {
if (i % 3 == 0 && i % 5 == 0) {
list.add("FizzBuzz");
} else if (i % 3 == 0) {
list.add("Fizz");
} else if (i % 5 == 0) {
list.add("Buzz");
} else {
list.add(String.valueOf(i));
}
}Method 2 - Using StringBuilder for String Concatenation
Method 3 - Using Streams (Java 8+)
Medium
Implement a method rand7() given rand5( )
Let’s take this:
a
b
5 * a + b
Last updated