Thursday, August 28, 2014

// // Leave a Comment

Java Program To Perform Simple Arithmetics

Program that performs arithmetics. The program is the answer to Deitel's Java How to Program (9th Edition) Chapter 2 Exercise 2.15: Write an application that asks the user to enter two integers, obtains them from the user and prints their sum, product, difference and quotient (division).


/**
 *
 * @author AGHATISE OSAZUWA
 * Website: www.cscprogrammingtutorials.com
 */

import java.util.Scanner;

public class Arithmetic {
    public static void main (String [] args) {
        
        Scanner value = new Scanner (System.in); // create a Scanner to obtain input from the user
        
        int num1; //first number entered by the user
        int num2; //second number entered by the user
        int add; //adds both numbers
        int difference; //subtracts the second number from the first
        int product; //multiplies both numbers
        int division; //divides the first number by the second number
        
        System.out.println ("Enter Your First Number");
        num1 = value.nextInt();
        System.out.println ("Enter Your Second Number");
        num2 = value.nextInt();
        
        add = num1 + num2;
        difference = num1 - num2;
        product = num1*num2;
        division = num1/num2;
        
        System.out.printf ("The Results Are: \nAddition = %d\nDifference = %d"
                + "\nProduct = %d\nQuotient = %d\n", add, difference, product, division);
    }
}


Click here to see other answers to Java How to Program.

0 comments:

Post a Comment


DISCLAIMER: Opinions expressed in comments are those of the comment writers alone and does not reflect or represent the views of the post author. We reserve the right to delete any post deemed inappropriate or offensive and/or spammy. Please do not use abusive words/hate speech.

I Appreciate your valuable Feedback. So, Please DO NOT SPAM - Spam comments will be deleted immediately.

Don't use brand name in name field and you're not allowed to use links in comments unless it's necessary. Such comments will be removed immediately.

Thanks.