public class AddWithoutPlus {
public static void main(String[] args) {
int num1 = 10;
int num2 = 5;
int sum = add(num1, num2);
System.out.print("Sum: ");
System.out.println(sum);
}
public static int add(int a, int b) {
while (b != 0) {
int carry = a & b;
a = a ^ b;
b = carry << 1;
}
return a;
}
}
Want 1 to 1 personalized Java training? Email me at isingh30 AT gmail please. View my following video
:
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.