In: Computer Science
Program Specifications
The built-in Java Math methods make some calculations much easier. Write a program called "DoTheMath" that accepts as input three floating-point numbers x, y, and z (define them as double) and outputs several calculations:
Sample Run:
Enter the values for x, y, z: -3.7 -3 5 <-- print a blank line before outputting calculations x to the power y is -0.019742167295125655 x to the power y to the power z is -8.452419664263233E-139 The absolute value of x is 3.7 The square root of x*y to the power z is 410.49459863681534 <-- end with a println
honestly just kind of lost on how to do this.
import java.util.Scanner;
public class DoTheMath {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the values for x, y, z:");
double x = in.nextDouble();
double y = in.nextDouble();
double z = in.nextDouble();
// <-- print a blank line before outputting calculations
System.out.println();
// x to the power y is -0.019742167295125655
System.out.println("x to the power y is " + Math.pow(x, y));
// x to the power y to the power z is -8.452419664263233E-139
System.out.println("x to the power y to the power z is " + Math.pow(x, Math.pow(y, z)));
// The absolute value of x is 3.7
System.out.println("The absolute value of x is " + Math.abs(x));
// The square root of x*y to the power z is 410.49459863681534 <-- end with a println
System.out.println("The square root of x*y to the power z is " + Math.sqrt(Math.pow(x*y, z)));
}
}
