CODE
import java.util.Scanner;
import java.io.*;
public class BinCalc2 {
public static void main(String[] args){
String str = new String();
String str2 = new String();
int carry = 0;
int[] result = new int[4];
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter first binary string");
Str bin[] = keyboard.next();
System.out.println("please enter second binary string");
Str bin2[] = keyboard.next();
for(int i = 2; i >= 0; i--){
int tempNum = Integer.parseInt(bin[i]);
int tempNum2 = Integer.parseInt(bin2[i]);
if((tempNum+tempNum2+carry) == 0){
result[i+1] = 0;
}else if((tempNum+tempNum2+carry) >= 2){
result[i+1] = 0;
carry = 1;
}else if((tempNum+tempNum2+carry) == 1){
result[i+1] = 1;
if(carry ==1){
carry = 0;
}
}
}
System.out.printf("%d + %d = %d", bin, bin2, result);
}
}
I keep getting errors when running the code
This post has been edited by Dark_Nexus: 20 Sep, 2007 - 11:57 PM