subtract two numbers without using arithmetic operators in java code example
Example: subtract two numbers without using arithmetic operators in java
public class SubtractWithoutArithmeticOperators
{
static int subtractNumber(int i, int j)
{
while(j != 0)
{
int carry = (~i) & j;
i = i ^ j;
j = carry << 1;
}
return i;
}
public static void main(String[] args)
{
int a = 23, b = 10;
System.out.println("a - b is " + subtractNumber(a, b));
}
}