**Write a program to enter two numbers and perform mathematical operations on them**

**Explanation:**

**Explanation:**

Hello friends so you have to **Write a program to enter two numbers and perform mathematical operations on them**

so how you are going to write java program to **perform mathematical ****operations** let’s see the logic going use behind this program

you have to perform **mathematical operations **and the basic mathematical operations are ( **+ **, **– **, **/ **, *****)

First you have to take user input using **Scanner** **class** and store it in two different **integer** variables **“number1”** and **“number2”**

then create three more **integer** variables to store **addition, subtraction, multiply **of two numbers and the variables names are **“add” , “sub”** **, “mul”**

and create one **Float** variable to store **division **of two variables and the variable name is **“div”**

first perform **addition** of two numbers and store the result in **“add” **variable [Ex: **add = number1 +number2;**]

Now perform **subtraction** of two numbers and store the result in **“sub” **variable [Ex: **sub = number1 +number2;**]

then perform multiplication of two numbers and store the result in **“mul” **variable [Ex: **mul = number1 +number2;**]

then perform divison of two numbers and store store the result in **“div” **variable [Ex: **div = number1 +number2;**]

and now print all the variables with their corresponding operations using **System.out.println(); **[Ex: **System.out.println(“Sum of two number : “+add);** ]

**program is given below follow it for reference**

**Check Out other post –****Write a program that calculate percentage marks of the student if marks of 6 subjects are given**

if you like the the way of explanation tell us in comment section you can also write the queries about this program we are defiantly going reply

share this post with your college friends so everyone can get benefit of it

**Program As per GTU Syllabus**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import java.util.Scanner; public class Program_3 { public static void main(String[] args) { int number1,number2,add,sub,mul; float div; Scanner scan = new Scanner(System.in);sp System.out.println("Enter Two Numbers :"); number1 = scan.nextInt(); number2 = scan.nextInt(); add = number1 + number2; sub = number1 + number2; mul = number1 + number2; div = number1 + number2; System.out.println("Sum of two number : "+add); System.out.println("subtraction of two number : "+sub); System.out.println("multiplication of two number : "+mul); System.out.println("division of two number : "+div); } } |