Description. USE JAVA Write a program using recursion to test whether a given number can be obtained by continuously mu

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Description. USE JAVA Write a program using recursion to test whether a given number can be obtained by continuously mu

Post by answerhappygod »

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
}

}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply