Created
April 21, 2016 22:58
-
-
Save booknara/6905f9b0aca372645a29b8cb77be604e to your computer and use it in GitHub Desktop.
Checking the number of power 3
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
/** | |
* Created by Daehee Han(@daniel_booknara) on 4/21/16. | |
*/ | |
public class Power3 { | |
public static void main(String[] args) { | |
for (int i = 1; i < 1000; i++) { | |
if (isPower3(i)) | |
System.out.println(i + " is power of 3"); | |
else | |
System.out.println(i + " is NOT power of 3"); | |
} | |
} | |
public static boolean isPower3(int value) { | |
while (value != 1) { | |
if (value % 3 != 0) | |
return false; | |
value = value / 3; | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment