Binary Calculator

need help, keep getting error, don't know how to fix

Page 1 of 1

1 Replies - 9705 Views - Last Post: 21 September 2007 - 01:46 AM Rate Topic: -----

#1 csbeginner  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 1
  • Joined: 21-September 07

Binary Calculator

Posted 21 September 2007 - 12:43 AM

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: 21 September 2007 - 12:57 AM


Is This A Good Question/Topic? 1
  • +

Replies To: Binary Calculator

#2 1lacca  Icon User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: Binary Calculator

Posted 21 September 2007 - 01:46 AM

Please post the errors you are getting, thank you.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1