-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFizzBuzzApp.java
More file actions
49 lines (46 loc) · 1.29 KB
/
Copy pathFizzBuzzApp.java
File metadata and controls
49 lines (46 loc) · 1.29 KB
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 mini_apps;
import java.util.Scanner;
/**
* user gives an integer n and the program prints the numbers 1,...,n but the numbers divisible by 3 get replaced with Fizz the ones
* with 5 get replaced by Buzz and those divisible by both of em by FizzBuzz
* @author Giannis
* @version 1.0.0
*/
public class FizzBuzzApp {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.print("Give an integer number: ");
int num = reader.nextInt();
int fizz = 2;
int buzz = 4;
int i = 1;
while ( i <= num) {
if ((fizz == 0) && (buzz == 0)) {
System.out.print(" FizzBuzz ");
fizz = 2;
buzz = 4;
i++;
continue;
}
if (buzz == 0) {
System.out.print(" Buzz ");
buzz = 4;
fizz--;
i++;
continue;
}
if (fizz == 0) {
System.out.print(" Fizz ");
fizz = 2;
buzz--;
i++;
continue;
}
System.out.print(" " + i + " ");
fizz--;
buzz--;
i++;
}
reader.close();
}
}