Question

A) write a program the computes nx and store the result into y You can use...

A) write a program the computes nx and store the result into y

You can use y = Math.pow( Mantissa, exponent)

Requirements:
Besides main() your program must have one method with two parameters, one double and one int

n and x are positive numbers read from the keyboard
if the user makes an entry that does not meet this criteria, the user must be given to opportunity retry the entry

the user must be able to quit prior to entering values for n and x

Your method must compute y and return the result to its caller; the caller will print the result

After printing the result, the user must be queried again if there are other values to compute; if the answer is no exit the program, but if the user replies yes, then repeat the computation

Homework Answers

Answer #1

Here is the required solution in java

here is the code

import java.util.*;
public class Main
{
   public static void main(String[] args) {
   Scanner sc=new Scanner(System.in);
   String s="yes";
   while(true)
   { //taking user input
   System.out.println("Enter value of Mantissa:");
   double Mantissa=sc.nextFloat();
   //input validation
   while(Mantissa<0)
   {
   System.out.println("Invalid input!.Enter again");
   Mantissa=sc.nextFloat();
   }
   System.out.println("Enter value of exponent:");
   int exponent=sc.nextInt();
   while(exponent<0)
   {
   System.out.println("Invalid input!.Enter again");
   exponent=sc.nextInt();
   }
   //call the method
   double result=fun(Mantissa,exponent);
   //print Result
       System.out.println("Result is :"+result);
       //check if user wants to continue or not
       System.out.println("Enter yes to continue or no to exit:");
       s=sc.next();
       if(s.equals("no"))
       break;
   }
   }//method defination to return Mantissa to the power exponent
   public static double fun(double Mantissa,int exponent)
   {
   return Math.pow(Mantissa,exponent);
   }
}

Know the answer?
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
Similar Questions
In this assignment you will write a program that compares the relative strengths of two earthquakes,...
In this assignment you will write a program that compares the relative strengths of two earthquakes, given their magnitudes using the moment magnitude scale. Earthquakes The amount of energy released during an earthquake -- corresponding to the amount of shaking -- is measured using the "moment magnitude scale". We can compare the relative strength of two earthquakes given the magnitudes m1 and m2 using this formula: f=10^1.5(m1−m2) If m1>m2, the resulting value f tells us how many times stronger m1...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
In this project you implement a program such that it simulates the process of repeated attempts...
In this project you implement a program such that it simulates the process of repeated attempts to hit a target with a projectile. The goal is to shoot the projectile within a 1 foot distance from the target, since such a short miss is accepted as a hit. Your program is responsible for the following tasks. Compute the trajectory data of a projectile (such as the time, the maximum height and the distance as described by the formulas above) for...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world applications. In your summary, provide an example of a software project that you can create using STL templates and provide a brief explanation of the STL templates you will use to create this project. After that you will implement the software project you described . Your application must be a unique project and must incorporate the use of an STL container and/or iterator and...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code to initialize the CustomerAccountsDB database table and add a set of customer accounts is provided. Finish the code in these 3 methods in CustomerAccountDB.java to update or query the database: -purchase(double amountOfPurchase) -payment(double amountOfPayment) -getCustomerName() Hint: For getCustomerName(), look at the getAccountBalance() method to see an example of querying data from the database. For the purchase() and payment() methods, look at the addCustomerAccount() method...
In java create a dice game called sequences also known as straight shooter. Each player in...
In java create a dice game called sequences also known as straight shooter. Each player in turn rolls SIX dice and scores points for any sequence of CONSECUTIVE numbers thrown beginning with 1. In the event of two or more of the same number being rolled only one counts. However, a throw that contains three 1's cancels out player's score and they mst start from 0. A total of scores is kept and the first player to reach 100 points,...
I've posted this question like 3 times now and I can't seem to find someone that...
I've posted this question like 3 times now and I can't seem to find someone that is able to answer it. Please can someone help me code this? Thank you!! Programming Project #4 – Programmer Jones and the Temple of Gloom Part 1 The stack data structure plays a pivotal role in the design of computer games. Any algorithm that requires the user to retrace their steps is a perfect candidate for using a stack. In this simple game you...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT