forked from dario-campagna/FizzBuzz-assignment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FizzBuzz.java
49 lines (43 loc) · 1.29 KB
/
FizzBuzz.java
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package dssc.assignment.fizzbuzz;
/**
* FizzBuzz assignment
* We want to write a Java program that prints the numbers from 1 to 100 to the
* "standard" output stream and follows these rules.
*
* For multiples of 3 it prints Fizz instead of the number.
* For multiples of 5 it prints Buzz instead of the number.
* For numbers which are multiples of both 3 and 5 it prints FizzBuzz.
*/
public class FizzBuzz {
public static void main(String... args) {
for(int i = 1; i <= 100; i += 1){
if (i % 3 == 0){
System.out.printf("Fizz");
}
if (i % 5 == 0){
System.out.printf("Buzz");
} else {
if (i % 3 != 0) {
System.out.printf("" + i);
}
}
System.out.println("");
}
// Interesting version
// boolean flag = true;
// for(int i=0;i<16;i++){
// if(i%3==0){
// System.out.print("Fizz");
// flag=false;
// }
// if(i%5==0){
// System.out.print("Buzz");
// flag=false;
// }
// if (flag)
// System.out.print(i);
// System.out.print(",");
// flag = true;
// }
}
}