Welcome to Dream.In.Code
Become a Java Expert!

Join 149,609 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,852 people online right now. Registration is fast and FREE... Join Now!




Binary Calculator

 
Reply to this topicStart new topic

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

csbeginner
20 Sep, 2007 - 11:43 PM
Post #1

New D.I.C Head
*

Joined: 20 Sep, 2007
Posts: 1


My Contributions
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
User is offlineProfile CardPM
+Quote Post

1lacca
RE: Binary Calculator
21 Sep, 2007 - 12:46 AM
Post #2

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
Please post the errors you are getting, thank you.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 12:16AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month