Question: Design a Java application that takes a positive integer number n 2 from the user and checks whether or not it can be represented as

Design a Java application that takes a positive integer number n 2 from the user and checks whether or not it can be represented as a sum of two integer powers of 3 (powers of 3 are numbers of the form 3k with k 0 being an integer, such as 9 = 32 for k = 2 and 27 = 33 for k = 3). If such representation is possible, it must be printed out. Otherwise, the string "representation is impossible" must be printed. For example, if n = 12, then it can be represented as the sum 3 + 9 with both 3 and 9 being powers of 3, so your program must output 12 = 3 + 9. Also, if n = 10 is given, your program must output 10 = 1 + 9 (here 1 = 30). Your code must work for any given n, not just for the above examples. Implement the following method boolean isPowerOf3(int m) in your code to check if a given number m is a power of 3. If this is the case, the return value is true and false otherwise. Within this method divide the number several times by 3 till the quotient reaches 1 and check the remainder.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!