## Java Program to Divide Two Numbers In this article, You will learn the topic of the Java Program to Divide Two Numbers. We can use the “/” division operator to divide two numbers using java program. Let’s see the possibilities to execute a task here.

Contents

## Java Program to Divide Two Numbers

We can use the “/” division operator directly to divide two numbers in java here.

``````public class Exercise3 {

public static void main(String[] args) {
System.out.println(49/7);
}

}``````

## Execution

In this program, We have to declare the dividend and divisor input values along with the “/” division operator. After executing this program, Both dividend and divisor values will be divided using the “/” division operator.

Finally, We will get and see the quotient output value on the output screen directly using the system.out.printIn() function.

## Output

The example output will provide below for your reference

``7``
`Read Also : Java Program to Add Two Numbers`

## Note

If you want to learn the concepts of Divide Two Numbers in C and Divide Two Numbers in C++ then please read those tutorials which we have already shared on our webpage.

## Java Program to Divide Two Numbers

Here, We can divide two numbers in java program based on the user input values.

``````import java.util.Scanner;

public class Main {
public static void main(String[] args)
{
Scanner input = new Scanner (System.in);
System.out.print("Input the first number: ");
int a = input.nextInt();
System.out.print("Input the second number: ");
int b = input.nextInt();
int d = (a/b);
System.out.println();
System.out.println("The division of a and b is:" +d);
}
}``````

## Explanation

As usual, We need to import the java.util.scanner class into this program. After that, We need to declare the respective variables to store the input and output values.

After executing this program, The program asks to provide the input integers by a user. The output will be divided using the “/” division operator along with the new scanner() class after applying the input values.

The calculated output will be stored in the new variable. Finally, The output will display on the screen using the system.out.printIn() function.

## Output

The example output of the java program to divide two numbers will be shown below for your reference.

``````Input the first number: 18
Input the second number: 9

The division of a and b is:2``````

## Final Thoughts

I hope this article helps you to Divide Two Numbers using Java. If you face any issues please let me know via the comment section. Share this article with other Java developers via social networks. Thank You!

### Manoj S

Hi, I'm Manoj working as a part-time blogger in Coding Diksha. Here, I post about programming to help developers.