Write a Java Program to Perform Mathematical Operations

By | 07.02.2017

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

 

5 1 vote
Article Rating
Category: Basic Programs Java Programming Tags:

About Tunde A

My name is Tunde Ajetomobi, a Tech Enthusiast and Growth Hacker. I enjoy creating helpful content that solves problem across different topics. Codezclub is my way of helping young aspiring programmers and students to hone their skills and find solutions on fundamental programming languages.

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments