forked from codec-akash/DSA-PS-Java-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFizzBuzz.java
More file actions
25 lines (21 loc) · 692 Bytes
/
FizzBuzz.java
File metadata and controls
25 lines (21 loc) · 692 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
public class FizzBuzz {
/**
* Write a program that prints the numbers from 1 to 100 and for multiples of '3' print "Fizz"
* instead of the number and for the multiples of '5' print "Buzz".
* @param args
*/
public static void main(String[] args) {
System.out.println("FizzBuzz");
for(int i=1; i<=100; i++){
if(i % 3 == 0 && i % 5 ==0){
System.out.println("FizzBuzz");
} else if (i % 5 ==0){
System.out.println("Buzz");
} else if(i % 3 ==0){
System.out.println("Fizz");
} else {
System.out.println(i);
}
}
}
}