Write a Program that Display Division of Two Numbers

Share:

Write a Program that Display Division of Two Numbers

In this article, we will learn how to write that display Division of Two Numbers program of java. We can Divide two numbers java program. 
Java Program by TechnoNiit

Division of Two Numbers are simple program that outputs  "8 / 2 = 4" on the screen. Since it's a very simple program, it's often used to introduce a new programming language to a newbie.

For Executing any java program, you need to

  • Install the JDK if you don't have installed it, download the JDK and install it.
  • Set path of the jdk/bin directory.
  • Create the java program
  • Compile and run the java program
//Division of Two Numbers Program in java

class ExampleDivide
{
    public static void main(String args[])
    {
      int a=8;
      int b=2;
      int c=(a/b);

      //first way to print result
     System.out.println(c);

     //second way to print result
     System.out.println("Division of Two Numbers:"
     +a+"/"+b+" = "+c);
    }
}
//Division of Three Numbers Program in java

public class ExampleDivide 
  {
    public static void main(String args[])
    {
      int a=8, b=4, c=2;
      int d=((a/b)/c);

      //first way to print result
     System.out.println(d);

     //second way to print result
     System.out.println("Division of Three Numbers:"
     +a+"/"+b+"/"+c+" = "+d);
    }
  }

If you have copied the exact code, you need save the file name as ExampleDivide.java. It's because the name of the class and filename should match in Java.

Compile: javac ExampleDivide.java

Execute: java ExampleDivide


You May Also Like:

Sum of Two and Three Numbers in java

Subtract of Two and Three Numbers in java

Multiplication of Two and Three Numbers in java

That’s it. Now you have successfully print Division of Two & Three Numbers Program in Java. If you have any doubt or question comment down below.

If you want to see the video of Division of two numbers, then watch the video below.



I hope this post will useful to you, Thanks For Visiting, Keep Visiting.

No comments