Computer Science, asked by Anonymous, 6 months ago

Write a program in java to find the sum of two numbers without using + operator. ​

Answers

Answered by Anonymous
0

Explanation:

Iterative Solution to add two integers without using Arithmetic operator

int carry = (a & b) ; //CARRY is AND of two bits.

a = a ^b; //SUM of two bits is A XOR B.

b = carry << 1; //shifts carry to 1 bit to calculate sum. }

return a; }

Answered by anindyaadhikari13
5

Question:-

Write a program in java to find the sum of two numbers without using + operator.

Program:-

import java.util.*;

class Sum

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

System.out.print("Enter first number: ");

int a=sc.nextInt();

System.out.print("Enter second number: ");

int b=sc.nextInt();

int s=a-(-b);

System.out.print("Sum is: ");

System.out.print(s);

}

}

I haven't used + operator.

This is the required answer for the program.

Similar questions