Read Java Interview Questions and Answers for Beginners and Experienced

Java Division operator Example

In this Java examples of Java tutorial, we will study about Java division operator with example. We will study what is the use of Java division operator.

 


Java division operator

Java division operator is used to divide the one number by another number. Java division operator is written as

Java division operator :  X / Y

• Here X and Y are two numbers
• / is the java division operator.

 


Java division operator Example

Let’s understand Java division operator with example.

public class JavaExamples {

public static void main(String[] args) {
//Java division operator with example in Java
int firstNumber=20;
int secondNumber=10;
int result=firstNumber / secondNumber;
System.out.print("result is:"+result);

}

}

output

result is:2

Explanation
In above Java division operator program, firstNumber and secondNumber are two integer variables. We applied Java division operator on these two numbers. We save the result in result variable.

In this Java operators with example, we saw how Java division operator works with example.