-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFizzBuzz.java
More file actions
29 lines (26 loc) · 791 Bytes
/
FizzBuzz.java
File metadata and controls
29 lines (26 loc) · 791 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
29
public class FizzBuzz {
// Method to calculate logic for fizzBuzz, if a number is divisible. and return
// the value
public String fizzBuzz(int val) {
if (val % 3 == 0 && val % 5 == 0) {
return "FizzBuzz";
} else if (val % 3 == 0) {
return "Fizz";
} else if (val % 5 == 0) {
return "Buzz";
} else {
return Integer.toString(val);
}
}
// Method to loop to 100 and feed the number of the loop to our helper method
public void fizzBuzzCounter() {
for (int i = 1; i <= 100; i++) {
String result = fizzBuzz(i);
System.out.println("Number: " + i + " - " + " Result: " + result);
}
}
// Method that can run without an object being created
public static void sayHello() {
System.out.println("Hello!!!!!");
}
}