Question

Comp Sci JAVA Log program using controls and loops 1. (1 point) Asks the user to...

Comp Sci JAVA Log program using controls and loops

1. (1 point) Asks the user to enter an integer base b > 1. (1 point) If the user enter anything less than or equal to 1, you should quit the program. 2. (1 point) Asks the user to enter a positive integer x greater than 0. (2 points) If the user enter anything less than or equal to 0, you should keep asking the user to re-enter a new number until the user enter a valid value. 3. (3 points) Calculate the floor of logb x in the manner indicated above and outputs the result 4. (2 points) Repeats until the user enters b less than or equal to 1 in step 1 The following is an example of a run:

Log base b of x Calculator Please enter a base b (> 1): 10 Please enter a value x (> 0): 123456 Log base 10 of 123456 is 5 Please enter a base b (> 1): 2 Please enter a value x (> 0): 64 Log base 2 of 64 is 6 Please enter a base b (> 1): 10 Please enter a value x (> 0): -123 Invalid value for x...Please enter a value x (> 0): 4567 Log base 10 of 4567 is 3 Please enter a base b (> 1): 0 Goodbye...

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts, please give me comment...

import java.util.Scanner;

public class LogProgram{

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

System.out.println("Log base b of x Calculator");

while(true){

System.out.print("Please enter a base b (> 1):");

int b = in.nextInt();

if(b==0){

System.out.println("Good Bye...");

break;

}

while(b<0){

System.out.println("Invalid value for b...");

System.out.print("Please enter a base b (> 1):");

b = in.nextInt();

}

System.out.print("Please enter a value x (> 0):");

int x = in.nextInt();

while(x<=0){

System.out.println("Invalid value for x...");

System.out.print("Please enter a value x (> 0):");

x = in.nextInt();

}

int result = (int)(Math.log(x)/Math.log(b));

System.out.println("Log base "+b+" of "+x+" is "+result);

}

}

}

Add a comment
Know the answer?
Add Answer to:
Comp Sci JAVA Log program using controls and loops 1. (1 point) Asks the user to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a java program that asks the user to enter an integer. The program should then...

    Write a java program that asks the user to enter an integer. The program should then print all squares less than the number entered by the user. For example, if the user enters 120, the program should display 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, and 100.

  • This is for Program in C Write a program that asks the user for an integer...

    This is for Program in C Write a program that asks the user for an integer with the prompt "Please enter an integer" using the puts function. Write the definition of a function isSenior, which receives an integer parameter and returns true if the parameter's value is greater or equal to 65, and false otherwise. So if the parameter's value is 7 or 64 or 12 the function returns false. But if the parameter's value is 69 or 83 or...

  • Design a Java program that asks the user to enter an integer number n and then...

    Design a Java program that asks the user to enter an integer number n and then generates an array of that many random points (x, y) with x- and y-coordinates in the range between 0 and 100. After this the program must ask the user to enter two diagonal points (x_1, y_1) and (x_2, y_2) of a rectangle with sides parallel to the coordinate axis (see the image below, where possible pairs of diagonal points are shown in red color)....

  • HELP IN JAVA: WHILE LOOP: Write a program that asks the user to enter a number...

    HELP IN JAVA: WHILE LOOP: Write a program that asks the user to enter a number of seconds. This number should be less than or equal to 32767 because that is the largest number pep8 can handle. Your program should then output the number of hours, minutes, and seconds on the planet of Crypton, where there are 64 seconds in a minute and 32 minutes in an hour.

  • Write a program that asks the user to enter number, and displays all the numbers that...

    Write a program that asks the user to enter number, and displays all the numbers that are multiples of 2 and 5 smaller than or equal to the number entered by the user. Hint: A number n is a multiple of 2 if the remainder of the division of n by 2 is equal to zero. Your program should have an output similar to the following: Please enter a number: 50 The multiples of 2 and 5 less than or...

  • We use JAVA. Thanks.    Create an application whose main method asks the user to enter...

    We use JAVA. Thanks.    Create an application whose main method asks the user to enter an n by m integer matrix that contains nm integer numbers. n and m should be between 1 and 10. If the user enters a             number less than 1 or greater than 10, the program will continue to ask the user to enter an integer number between 1 and 10. The program should print the sum of the boundary elements of the matrix....

  • USING PYTHON 1. Write a small program that asks for an integer number from the user...

    USING PYTHON 1. Write a small program that asks for an integer number from the user and print all the prime numbers (2,3,5,7,etc) less than the input number. 2. How long it takes for your program to print the prime numbers less than 100. (Use magic functions)

  • Its java class pratice  problem (Geometry: point in a rectangle?) Write a program that prompts the user...

    Its java class pratice  problem (Geometry: point in a rectangle?) Write a program that prompts the user to enter a point (x, y) and checks whether the point is within the rectangle centered at (0, 0) with width 10 and height 5.  For example, (2, 2) is inside the rectangle and (6, 4) is outside the rectangle. (Hint: A point is in the rectangle if its horizontal distance to (0, 0) is less than or equal to10 / 2 and...

  • 2. Write a C++ program that asks the user to enter a integer between 1 and...

    2. Write a C++ program that asks the user to enter a integer between 1 and 10. Continue to prompt the user while the value entered does not fall within the range. When the user is successful display a congratulatory message. Save file as OneToTen.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT