Code Below:


import java.util.*;
class Binary_Add
{
    long bin1,bin2,sum;
    Binary_Add()
    {
        bin1=0;
        bin2=0;
    }
    void input()
    {
        Scanner s=new Scanner(System.in);
        System.out.println("enter 2 nos.");
        bin1=s.nextLong();
        bin2=s.nextLong();
    }
    void calculate()
    {
        String str1=Long.toString(bin1);
        String str2=Long.toString(bin2);
        int len1=str1.length();
        int len2=str2.length();
        int max=Math.max(len1,len2);
        int min=Math.min(len1,len2);
        String su="";int k=0;
        for (int i=1; i<=max-min; i++)
        if (len1==min)
        str1="0"+str1;
        else
        str2="0"+str2;
        for (int j=max-1;j>=0;j--)
        {
            char ch1=str1.charAt(j);
            char ch2=str2.charAt(j);
            int s=(ch1-48)+(ch2-48)+k;
            switch (s)
            {
                case 0:su="0"+su;
                k=0;
                break;
                case 1:su="1"+su;
                k=0;
                break;
                case 2:su="0"+su;
                k=1;
                break;
                case 3:su="1"+su;
                k=1;
                break;
            }
        }
        sum=Long.parseLong(k+su);
    }
    void display()
    {
        System.out.print(bin1+"+"+bin2+"=");
        System.out.print(sum);
    }
    public static void main()
    {
        Binary_Add obj=new Binary_Add();
        obj.input();
        obj.calculate();
        obj.display();
    }
}