Created
March 24, 2015 14:19
-
-
Save hanaori/6f86c0cdf6d0fbaf5a74 to your computer and use it in GitHub Desktop.
FizzBuzz without using modulo "%"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FizzBuzz { | |
public void getResultOfFizzBuzz(){ | |
for(int i = 1; i <= 100; i++){ | |
if(calcRemainder(i, 3) == 0 && calcRemainder(i, 5) == 0){ | |
System.out.println("FizzBuzz"); | |
}else if(calcRemainder(i, 3) == 0){ | |
System.out.println("Fizz"); | |
}else if(calcRemainder(i, 5) == 0){ | |
System.out.println("Buzz"); | |
}else{ | |
System.out.println(i); | |
} | |
} | |
} | |
private int calcRemainder(int num, int divisor){ | |
while(num >= divisor){ | |
num = num - divisor; | |
} | |
return num; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment