-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFizzBuzz.java
More file actions
28 lines (26 loc) · 835 Bytes
/
Copy pathFizzBuzz.java
File metadata and controls
28 lines (26 loc) · 835 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
26
27
28
class Scratch {
public static void main(String[] args) {
int start = 1;
int max = 100;
ConsoleBasedFizzBuzz buzzer = new ConsoleBasedFizzBuzz();
buzzer.print(start, max);
}
interface FizzBuzz {
void print (int from, int to);
}
static class ConsoleBasedFizzBuzz implements FizzBuzz {
public void print (int from, int to) {
for (int i = from; i <= to; 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);
}
}
}
}
}