Arithmetic Operator in JAVA

 There are different types of operators in java programming language. one of them is arithmetic operator. Arithmetic operators are used to do arithmetic operations in java. The sign used on arithmetic operation are listed below.

1) Addition + 

2) Subtraction -

3) Division /

4) Multiplication *

5) Modulo % ( It gives reminder after division)

Example below displays the source code of performing arithmetic operation. 


package operators;


public class ArithmeticOperators {

// basically there are 5 types of arithmetic operator

// 1) addition +

// 2) Subtraction -

// 3) multiplication *

// 4) division /

// 5) modulo %

public static void main(String[] args) {

int a = 10;

int b = 22;

// lets do addition first

System.out.println("Total sum = " + (a + b));

// subtraction

System.out.println("b - a = " + (b - a));

// multiplication

System.out.println("a * b = " + (a * b));

// division

System.out.println("a / a = " + (b / a));

// modulo > it displays remainder

System.out.println("a % b = " + (b % a));

}

}

Output when source code executed
==========================================

Total sum = 32
b - a = 12
a * b = 220
a / a = 2
a % b = 2


At the very beginning inside main method, two variable are initialized and defined the value of a and b. Sysetm.out.println() is used to display the operation. Double quote is used to display the String value as it is. And + sign is used to concatenate the String with addition result. 

You can check the tutorial here: https://youtu.be/lTwbXQRAuN8 
Print Hello World: https://youtu.be/IVSwBZybcyI
How to install JDK: https://youtu.be/ecWr2Z-kgw8

Comments

Popular posts from this blog

Logical operator in JAVA

Class and Object in Java

Loop Structure