Purchase Solution

Simple Java program to add and subtract two numbers

Not what you're looking for?

Ask Custom Question

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.

Purchase this Solution

Solution Summary

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

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 ...

Purchase this Solution


Free BrainMass Quizzes
C# variables and classes

This quiz contains questions about C# classes and variables.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

Javscript Basics

Quiz on basics of javascript programming language.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

C++ Operators

This quiz tests a student's knowledge about C++ operators.