Menu

JAVA PROGRAM-SUM OF TWO NUMBERS WITHOUT USING + OPERATOR

import java.util.*;
class Sum_of_2numbers_without_plus{
public static void main(String args[]){

Scanner sc= new Scanner(System.in);
System.out.println("Enter two numbers to peform addition");
int n1=sc.nextInt();
int n2=sc.nextInt();
int carry;

while(n2!=0){
carry= n1 & n2;
n1= n1^n2;
n2=carry<<1;
}
System.out.println("The sum of two numbers is "+n1 );

}}