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 in java.

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("subtraction of two numbers = " + subtraction);
      sc.close();
   }
}


Output:

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


Also read – polymorphism in java


Never stop learning. Learn core java and learn coding.