Answers for "subtract two numbers without using arithmetic operators in java"

1

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));
   }
}
Posted by: Guest on February-18-2021

Code answers related to "subtract two numbers without using arithmetic operators in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language