-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFizzBuzz.java
More file actions
23 lines (21 loc) · 839 Bytes
/
FizzBuzz.java
File metadata and controls
23 lines (21 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*Question 1: FizzBuzz
* Write a program that prints the numbers from 1 to 100.For mutliples of 3 , print "Fizz"; for multiples of 5, print "Buzz"; and for numbers that are multiples of both 3 and 5, print "FizzBuzz".
*/
public class FizzBuzz {
public static void main(String[] args) {
// print the numbers from 1 to 100
// While checking if the number is divisible by 3 or 5 then printing the
// appropriate string.
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);
}
}
}
}