subtraction of two numbers in java

Let’s learn subtraction of two numbers in java.

subtraction of two numbers in java

Here’s the java program to subtract two numbers or java subtraction program.

import java.util.Scanner;
public class SubtractionOfTwoNumbers
{
   public static void main(String[] args)
   {
      int num1, num2, subtraction;
      System.out.println("Please enter two numbers to substract: ");
      Scanner sc = new Scanner(System.in);
      num1 = sc.nextInt();
      num2 = sc.nextInt();
      subtraction = num1 - num2;
      System.out.println("java program for subtraction of two numbers = " + subtraction);
      sc.close();
   }
}


Output:

Please enter two numbers to substract:
100
50
java program for subtraction of two numbers = 50


Also read – polymorphism in java