Description. USE JAVA Write a program using recursion to test whether a given number can be obtained by continuously mu
Posted: Fri May 20, 2022 12:29 pm
Description. USE JAVA
Write a program using recursion to test whether a given number can
be obtained by continuously multiplying 3 (how many powers of
3).
[CONDITIONS]
You cannot change or modify the code of a given code
template.
// Your code for method can only be coded in the powerOfThree
part.
You cannot create a method other than powerOfThree.
You cannot create and use another class.
Hint:
1) 0 is not a few powers of 3, and 1 is 3 powers 0.
2) Any number that is several powers of 3 must be divided by 3.
(i.e. the remainder when divided by 3 is 0)
NO input
sample output:
code template:
public class Main {
public static void main(String[] args)
{
int[] data = {0, 1, 3, 4, 9,
15, 18, 27, 29};
for (int i = 0; i <
data.length; i++) {
System.out.println("" + data + ": " +
powerOfThree(data));
}
}
static boolean powerOfThree(int n) {
// your code for method powerOfThree
}
}
Write a program using recursion to test whether a given number can
be obtained by continuously multiplying 3 (how many powers of
3).
[CONDITIONS]
You cannot change or modify the code of a given code
template.
// Your code for method can only be coded in the powerOfThree
part.
You cannot create a method other than powerOfThree.
You cannot create and use another class.
Hint:
1) 0 is not a few powers of 3, and 1 is 3 powers 0.
2) Any number that is several powers of 3 must be divided by 3.
(i.e. the remainder when divided by 3 is 0)
NO input
sample output:
code template:
public class Main {
public static void main(String[] args)
{
int[] data = {0, 1, 3, 4, 9,
15, 18, 27, 29};
for (int i = 0; i <
data.length; i++) {
System.out.println("" + data + ": " +
powerOfThree(data));
}
}
static boolean powerOfThree(int n) {
// your code for method powerOfThree
}
}