Package Level2;/*** Add Binary *** Given two binary strings, return their sum (also a binary string ). for example, a = "11" B = "1" Return "100 ". */public class S67 {public static void main (String [] args) {String a = "1111"; String B = "1111"; System. out. println (addBinary (a, B);} public static String addBinary (String a, String B) {int I =. length ()-1; // I points to int j = B at the end of. length ()-1; // j points to int c = 0 at the end of B; // carry // convert String to char array to facilitate processing char [] achar =. toCharArray (); char [] bchar = B. toCharArray (); // result array char [] reschar = new char [Math. max (achar. length, bchar. length) + 2]; int k = 0; // k points to the beginning of the result array while (true) {if (I <0 & j <0 & c = 0) {break;} int aint = 0; int bint = 0; if (I> = 0) {aint = achar [I]-'0';} if (j> = 0) {bint = bchar [j]-'0 ';} if (aint + bint + c> 1) {reschar [k] = (char) ('0' + aint + bint + c-2); c = 1 ;} else {reschar [k] = (char) ('0' + aint + bint + c); c = 0 ;} k ++; I --; j --;} // convert the char array to string, and then flip return new StringBuffer (new String (reschar, 0, k )). reverse (). toString ();}}