Java Division

Java Division Arithmetic operator takes two operands as inputs and returns the quotient of division of left operand by right operand.

/ symbol is used for Division Operator.

Syntax – Division Operator

Following is the syntax for Division Operator.

result = operand_1 / operand_2

The operands could be of any numeric datatype.

If the two operands are of different datatypes, implicit datatype promotion takes place and value of lower datatype is promoted to higher datatype.

Example 1 – Division of two Integers

In the following example, we shall take two integers and apply Division operation to find the quotient of division operation.

Java Program

</>
Copy
public class DivisionExample {
	public static void main(String[] args) {
		int a = 7;
		int b = 3;
		
		int result = a / b;
		System.out.print(result);
	}
}

Output

2

Example 2 – Division of two Numbers belonging to Different Datatypes

In the following example, we shall find the division of an integer with a float using Division Arithmetic Operator.

As the operand values are of two different datatypes, Java promotes the value with lower datatype to higher datatype and the result would be of higher datatype. In the following example, int is promoted to float, and the result is a floating point number.

Java Program

</>
Copy
public class DivisionExample {
	public static void main(String[] args) {
		int a = 7;
		float b = 3.1f;
		
		float result = a / b;
		System.out.print(result);
	}
}

Output

2.2580645

Conclusion

In this Java Tutorial, we learned how to use Java Division Operator.