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

Popular posts from this blog

Design and Develop a java program to read marks of a student and print the total and average of marks using scanner class.

Write a Java program to convert seconds to hour, minute and seconds.

Write a Java program to print the ascii value of a given character.