Skip to content

Instantly share code, notes, and snippets.

@booknara
Created April 21, 2016 22:58
Show Gist options
  • Save booknara/6905f9b0aca372645a29b8cb77be604e to your computer and use it in GitHub Desktop.
Save booknara/6905f9b0aca372645a29b8cb77be604e to your computer and use it in GitHub Desktop.
Checking the number of power 3
/**
* 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