1 건의
덧셈 검색결과




public static void main(String[] args) {


Scanner s = new Scanner(System.in);

System.out.printf("First binary number : ");

int bnum1 = s.nextInt();

System.out.printf("Second binary number : ");

int bnum2 = s.nextInt();

Integer[] sum = new Integer[10];

int csumy = 0;

int i = 0;

while( bnum1 != 0 || bnum2 != 0 | csumy != 0 ) {

sum[i++] = (bnum1 % 10 + bnum2 % 10 + csumy) % 2;

csumy = (bnum1 % 10 + bnum2 % 10 + csumy) / 2;

bnum1 = bnum1 / 10;

bnum2 = bnum2 / 10;

}

System.out.printf("Sum of two binaries : ");

while(i > 0) {

System.out.printf("%d",sum[--i]);

}

}