Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java: Here is my code. I'm getting an error when I try to run the program. It has to do with the formatted section of

Java: Here is my code. I'm getting an error when I try to run the program. It has to do with the formatted section of my code. If you could tell me what is wrong and what to fix that would be appreciated.

Code:

package smith6;

import java.util.Scanner;

public class MyMath { public static void totaldiff(double num1, double num2) { double sum; double difference;

sum = num1 + num2; if (num1 > num2) difference = num1 - num2; else difference = num2 - num1; System.out.println("The total of " + num1 + " and " + num2 + " is " + sum); System.out.println("The positive difference between " + num1 + " and " + num2 + " is " + difference); } public static double product (double num1, double num2) { double product; product = num1 * num2; return product;

}

public static double quotient (double num1, double num2) { if (num1 < num2) return num2 / num1; else return num1 / num2; } public static void main(String[] args) { double inputnum1; double inputnum2; Scanner input = new Scanner(System.in); System.out.println("Enter two double numbers: "); inputnum1 = input.nextDouble(); inputnum2 = input.nextDouble(); totaldiff(inputnum1, inputnum2); System.out.println(inputnum1 + " times " + inputnum2 + " = " + product(inputnum1, inputnum2)); System.out.printf("%.3f", inputnum2 + " divided by%.3f ", inputnum1 + " = " + "%.3f", quotient(inputnum1, inputnum2)); }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Moving Objects Databases

Authors: Ralf Hartmut Güting, Markus Schneider

1st Edition

0120887991, 978-0120887996

More Books

Students also viewed these Databases questions

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago