Created
July 22, 2018 23:49
-
-
Save jbrains/dbadc637ea9e088d49220acce830a1be to your computer and use it in GitHub Desktop.
Find the number of factors of 5 in natural number n
This file contains hidden or 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 static int factorsOfFiveIn(int n) { | |
int factorsOfFive = 0; | |
while (n > 1) { | |
if (n % 5 == 0) factorsOfFive++; | |
n /= 5; | |
} | |
return factorsOfFive; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As a post script, I found an alternative implementation of the larger exercise, which makes
factorsOfFiveIn()
obsolete. :) I'll publish the whole thing somewhere quite soon.