This is a Java program that demonstrates how to perform subtraction without using the minus (-) operator.
Note that this method of subtraction is not as efficient as using the minus operator, as it involves several bitwise operations and addition. It is provided here as an example of how to perform arithmetic operations using bitwise operators.
import java.util.Scanner; public class Subtract_WithoutMinus { public static void main(String[] args) { Scanner input = new Scanner(System.in); int num1 = 0, num2 = 0,sub = 0; System.out.printf("Enter the Number 1 : "); num1 = input.nextInt(); System.out.printf("Enter the Number 2 : "); num2 = input.nextInt(); sub = num1 + ~num2 + 1; System.out.println("Subtraction without using Minus(-) Operator.."); System.out.printf("Subtraction of %d - %d = %d", num1, num2, sub); } }
Enter the Number 1 : 23 Enter the Number 2 : 18 Subtraction without using Minus(-) Operator.. Subtraction of 23 - 18 = 5
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions