Java Program to Perform Mathematical Operations
Write a Java Program to Perform Mathematical Operations such as addition, subtraction, multiplication and division of any two number in Java Programming, you have to ask to the user to enter the two number and then perform the action accordingly.
Following Java Program ask to the user to enter the two number and perform the addition, subtraction, multiplication and division on the two entered number by the user and then display the result on the screen:
SOURCE CODE ::
import java.util.Scanner; public class mat_operations { public static void main(String args[]) { int a, b, res; Scanner scan = new Scanner(System.in); System.out.print("Enter Two Numbers : "); a = scan.nextInt(); b = scan.nextInt(); res = a + b; System.out.println("Addition = " +res); res = a - b; System.out.println("Subtraction = " +res); res = a * b; System.out.println("Multiplication = " +res); res = a / b; System.out.println("Division = " +res); } }
OUTPUT ::
Enter Two Numbers : 34 79 Addition = 113 Subtraction = -45 Multiplication = 2686 Division = 0