Question: Java program Create the following program: A main() method that asks the user to enter 3 integers, a, b, and c. main() will call add()

Java program

Create the following program:

A main() method that asks the user to enter 3 integers, a, b, and c. main() will call add() to add a+b and print the result. Next, main() will call divide() to divide a/c and print the result.

Prototypes for your arithmetic methods are:

// Computes n1+n2 and prints the result

public static void add (int n1, int n2);

// Computes n1/n2 and prints the result

public static void divide (int n1, int n2);

In both add() and divide() assert the following conditions on the input parameters to the methods:

In add():

n1 and n2 are both positive numbers

In divide():

n2 is not zero

For each assertion include a string in the assertion that describes the error being asserted. In the divide() method, exit the program after the assertion. In the add() method, allow the program to continue running after the assertion.

Run your program and test triggering one of the assertions.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!