In this tutorial, we are going to write a Java program for subtraction of two numbers in java programming with practical program code and step-by-step full complete explanation.

Java program for subtraction of two numbers


Java program for subtraction of two numbers

 
import java.util.Scanner;

public class Subtraction {
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        
        // Input two integers
        System.out.println("Enter a = ");
        int a = scanner.nextInt();
        System.out.println("Enter b = ");
        int b = scanner.nextInt();
        
        // Subtraction of a and b
        int sub = a-b;
        
        // Print Sub
        System.out.println("Subtraction = "+sub);
    }
}


Output

 
Enter a = 
5
Enter b = 
2
Subtraction = 3