1import java.util.Scanner;
2public class JavaExample {
3 public static void main(String[] args)
4 {
5 long b1, b2;
6 int i = 0, carry = 0;
7 int[] sum = new int[10];
8 Scanner scanner = new Scanner(System.in);
9 System.out.print("Enter first binary number: ");
10 b1 = scanner.nextLong();
11 System.out.print("Enter second binary number: ");
12 b2 = scanner.nextLong();
13 scanner.close();
14 while (b1 != 0 || b2 != 0)
15 {
16 sum[i++] = (int)((b1 % 10 + b2 % 10 + carry) % 2);
17 carry = (int)((b1 % 10 + b2 % 10 + carry) / 2);
18 b1 = b1 / 10;
19 b2 = b2 / 10;
20 }
21 if (carry != 0) {
22 sum[i++] = carry;
23 }
24 --i;
25 System.out.print("Output: ");
26 while (i >= 0) {
27 System.out.print(sum[i--]);
28 }
29 System.out.print("\n");
30 }
31}