Share
Explore BrainMass

Simple Java program to add and subtract two numbers

Create an application named Numbers. The Numbers class should have non-static public methods named sum and difference, each taking a pair of int variables as arguments. As you might expect, the sum method should add the two integers and return the sum; the difference method should find the difference between the two integers and return that value. The main method holds two int variables. Assign values to the variables (you can prompt for these values or hard code them). Instantiate an object from the Numbers class in the main method. Using the two integer variables, use the instantiated object to call the sum and difference methods and print the results. There should be no printing in the methods themselves, only in the main method. Save the application as Numbers.java.

Solution Preview

You can do something like this...

public class Numbers{

private int firstNumber;
private int secondNumber;
int result;

public int sum(int firstNumber, int ...

Solution Summary

Program to add and subtract two numbers passed as arguments to two methods.

$2.19