Skip to content

Commit

Permalink
Reduce duplication, introduce local variables
Browse files Browse the repository at this point in the history
  • Loading branch information
dmerejkowsky committed Aug 29, 2022
1 parent 9b24e44 commit 6d78714
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions java/src/main/java/fr/arolla/FizzBuzz.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ public class FizzBuzz {
* return the number a string
*/
public static String fizzBuzz(int number) {
if (number % 3 == 0 && number % 5 == 0) {
boolean divisibleBy3 = number % 3 == 0;
boolean divisibleBy5 = number % 5 == 0;

if (divisibleBy3 && divisibleBy5) {
return "fizzbuzz";
}
if (number % 3 == 0) {
if (divisibleBy3) {
return "fizz";
}
if (number % 5 == 0) {
if (divisibleBy5) {
return "buzz";
}

Expand Down

0 comments on commit 6d78714

Please sign in to comment.