Question: Java (While Loop) Maximum power of 3 lower or equal than n Given an integer variable n entered by the user from keyboard, complete the

Java (While Loop) Maximum power of 3 lower or equal than n

Given an integer variable n entered by the user from keyboard, complete the following code in order to figure what is the maximum power of 3 that is lower or equal than n. Store the result in an integer variable called maxPower. E.g. 1: if the value of n entered by the user is 2, the value of maxPower will be 1. E.g. 2: if the value of n entered by the user is 500, the value of maxPower will be 243. E.g. 3: if the value of n entered by the user is 27, the value of maxPower will be 27.

import java.util.Scanner;

public class Lab4 { public static void main(String[] args){ // Create a scanner to read from keyboard Scanner kbd = new Scanner (System.in); // Prompt user for typing a numeric input System.out.print("Enter value of n: "); //Stores the integer value from keyboard in the variable n int n = kbd.nextInt(); int maxPower; //YOU MUST NOT WRITE ANY CODE ABOVE THIS LINE

//YOU MUST NOT WRITE ANY CODE BELOW THIS LINE System.out.println(maxPower); } }

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!