-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIsPowerOfFive.java
More file actions
37 lines (28 loc) · 862 Bytes
/
IsPowerOfFive.java
File metadata and controls
37 lines (28 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package org.simplemedium;
public class IsPowerOfFive {
public static void main(String[] args) {
System.out.println("Hello world!");
int[] testNumbers = {1, 5, 25, 30, 125, 0, -5, 29};
for (int number : testNumbers) {
if (checkIsPowerOf5(number, 5))
System.out.println(number + " is power of 5");
else
System.out.println(number + " is NOT power of 5");
}
}
private static boolean checkIsPowerOf5(int n, int p) {
try {
if (n < p)
return false;
while (n % p == 0) {
n = n / p;
}
return n == 1;
}
catch(Exception e) {
System.out.print("There is an exception: " );
e.printStackTrace();
return false;
}
}
}