Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.
import java.util.Scanner;
/**
* Created by Tao on 2017/2/6.
*/
public class _371 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y = sc.nextInt();
int result = mySum(x,y);
System.out.println(result);
}
public static int mySum(int a, int b) {
int sum;
int carry;
int num1 = a;
int num2 = b;
do {
sum = num1 ^ num2;
carry = (num1 & num2) << 1;
num1 = sum;
num2 = carry;
} while (carry != 0);
return sum;
}
}