Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

define a method printcalculation() that has two double parameters, and …

Question

define a method printcalculation() that has two double parameters, and outputs outcome: followed by the result of dividing the first parameter by the second parameter with a precision of one digit as follows. end with a newline.
ex: if the input is -11.0 -10.0, then the output is:
outcome: 1.1
note:

  • the calculation to find the division of two values x and y is (x / y).
  • system.out.printf(\%.1f\, mydouble) outputs mydouble with a precision of one digit.
  • the denominator is always non - zero.

1 import java.util.scanner;
2
3 public class calculation {
4
5 / your code goes here /
6
7 public static void main(string args) {
8 scanner scnr = new scanner(system.in);
9 double a;
10 double b;
11
12 a = scnr.nextdouble();
13 b = scnr.nextdouble();
14
15

Explanation:

Step1: Define the method

The method printCalculation has two double parameters x and y.

public static void printCalculation(double x, double y) {

Step2: Calculate and print

Calculate x / y and print with one - digit precision.

    System.out.printf("Outcome: %.1f
", x / y);
}

Answer:

public static void printCalculation(double x, double y) {
    System.out.printf("Outcome: %.1f
", x / y);
}