Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke

4th Edition

0136086535, 9780136086536

Students also viewed these Databases questions

Question

=+j Describe an effective crisis management program.

Answered: 1 week ago