# Addition, Difference, Product, and Quotient in Java

Oct 15, 2021

Machine Problem

Write a Java program to print the addition, difference, multiply, divide of two numbers.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

Program Listing

``````/*
*  Math.java
*
*  Jake Rodriguez Pomperada, MAED-IT, MIT
*  Bacolod City, Negros Occidental Philippines
*
* Machine Problem
*
* Write a Java program to print the addition,difference, multiply, divide of two numbers.
*/

import java.util.Scanner;
import java.math.RoundingMode;
import java.text.DecimalFormat;

public class Math {

private static DecimalFormat df2 = new DecimalFormat("#.##");

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.println();
System.out.println("\tAddition, Difference, Product, and Quotient in Java");
System.out.println();

System.out.print("\tEnte First Number : ");
double val_1 = input.nextDouble();

System.out.print("\tEnter Second Number : ");
double val_2 = input.nextDouble();

System.out.println();
System.out.println("\tThe sum between " + val_1 + " and " + val_2 + " is " + (val_1 + val_2) + "." );
System.out.println("\tThe difference between " + val_1 + " and " + val_2 + " is " + df2.format((val_1 - val_2)) + "." );
System.out.println("\tThe product between " + val_1 + " and " + val_2 + " is " + df2.format((val_1 * val_2)) + "." );
System.out.println("\tThe quotient between " + val_1 + " and " + val_2 + " is " + df2.format((val_1 / val_2)) + "." );

System.out.println();
System.out.println("\tEnd of Program");
System.out.println();
}

}``````