Write a Java program to add two numbers without using any arithmetic operators. Given x = 10 and y = 12; result = 22
/*Write a Java program to add two numbers without using any arithmetic
operators.
Given x = 10 and y = 12; result = 22*/
import java.util.*;
class Third
{
public static void main(String arg[])
{
Scanner obj = new Scanner ( System.in );
int a, b, c;
System.out.print("\nEnter value for A: ");
a = obj.nextInt();
System.out.print("Enter value for B: ");
b = obj.nextInt();
while(b!=0)
{
c = a & b;
a = a^b;
b=c<<1;
}
System.out.println("\nSum is : "+a);
}
}
More Information on our channel Programmer Community
please like , share and subscribe to get notifications of new videos....
To understand this program video will coming soon on our you tube channel
Comments
Post a Comment