jump to level 1\ncompute: $d = (sqrt{b - c})^3$\nex: if the input is 5.00 1.00, then the output is:\n8.00\n1…

jump to level 1\ncompute: $d = (sqrt{b - c})^3$\nex: if the input is 5.00 1.00, then the output is:\n8.00\n1 import java.util.scanner;\n2\n3 public class mathmethods {\n4 public static void main(string args) {\n5 scanner scnr = new scanner(system.in);\n6 double b;\n7 double c;\n8 double d;\n9\n10 b = scnr.nextdouble();\n11 c = scnr.nextdouble();\n12\n13 /* your code goes here */\n14\n15 system.out.printf(\%.2f\\n\, d); // outputs d with 2 decimal places\n
Answer
Explanation:
Step1: Subtract c from b
First, calculate the value inside the square - root, i.e., $x = b - c$.
Step2: Take the square - root
Then, find the square - root of the result from Step 1, $y=\sqrt{x}$.
Step3: Cube the result
Finally, cube the result from Step 2, $d = y^{3}$.
If we assume the input values $b = 5.00$ and $c = 1.00$:
- Step1: $x=b - c=5.00 - 1.00 = 4.00$.
- Step2: $y=\sqrt{4.00}=2.00$.
- Step3: $d = 2.00^{3}=8.00$.
In Java code (filling in the missing part of the given code):
import java.util.Scanner;
public class MathMethods {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
double b;
double c;
double d;
b = scnr.nextDouble();
c = scnr.nextDouble();
d = Math.pow(Math.sqrt(b - c), 3);
System.out.printf("%.2f\n", d);
}
}
Answer:
The Java code to complete the computation is:
import java.util.Scanner;
public class MathMethods {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
double b;
double c;
double d;
b = scnr.nextDouble();
c = scnr.nextDouble();
d = Math.pow(Math.sqrt(b - c), 3);
System.out.printf("%.2f\n", d);
}
}