Beginners Programs :

Java Program For Addition, Subtraction, Multiplication, Division | Programs

Java program for Addition, Subtraction, Multiplication and Division. Here we will discuss the most common mathematical operations such as addition, subtraction, multiplication and division In java. The compiler has been added as well so that you can execute the programs yourself, along with suitable examples and sample outputs. The programs as aforementioned are:

  • Addition.
  • Addition using Static Method.
  • Subtraction.
  • Multiplication.
  • Multiplication without using the Multiplication(*) operator.
  • Division.
  • Division without using the Division (/) operator.

Java Program – Addition

1) We are using the standard formula for adding two numbers.c=a+b.

2) Read the values using scanner object sc.nextInt() and store these values in the variables a,b and calculate addition of a,b and print the c value.

Addition(Using Static Method)

1) addition(int x, int y) is the static method, which calculates the addition of two numbers and returns the value.

2) addition(a,b) method calls at the main method then that static method calculates the addition of two numbers and returns the value and value will be assigned to the variable c.

Subtraction Java Program

1) We are using the formula for subtraction is c=a-b.

2) Read the values using scanner object sc.nextInt() and store these values in the variables a,b. Subtract the smaller value from bigger value and result will be assigned to c and print the c value.

Java Multiplication Program

1) The formula for multiplication of two numbers is c=a*b.

2) Read the values using scanner object sc.nextInt() and store these values in the variables x,y and calculate multiplication of these numbers then print the z value.

Multiplication of two numbers without using the Multiplication(*) operator

1) We are calculating the multiplication of two numbers without using “*” operator.

2) Read the values using scanner object sc.nextInt() and store these values in the variables x,y.

3) If the condition at while x!=0 is true then z=(z+y) and x value decreased by 1, repeats until x!=0. If x=0 then while loop terminates then print the z value.

Division

1) The standard formula for division of two numbers is  c=a/b where b!=0.

2) Read the numerator and denominator values using scanner object sc.nextInt() and store these values in the variables n,d and calculate the division of these numbers then print the “res” value.

Division of two numbers without using the Division(/) operator

1) We are calculating the division of two numbers without using the “/” operator.

2) Read the numerator and denominator values using scanner object sc.nextInt()  and store these values in the variables a,b. if b!=0 then a=a-b, and c value increased by 1 until  the condition at  while a>=b is false.After all the iterations, it prints the c value.

More Java Programs: