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
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);
}
}
Get Answers For Free
Most questions answered within 1 hours.