I need help

• March 22nd, 2011, 04:10 PM
marijana_ristova
I need help
hey,
I`m new in this forum and this is my first experiance in such forums....
Something about me: my name is Marijana, I`am a 19 years old and i am study...and don`t know what to say another...
Now I need help from you.My code below is for multipling two binary number in IEEE 735 standard and I have this
Code Java:

```package proekt2;   public class ArrayUtils{   static String[] lookupTable = { "0+0+0=00", "0+0+1=01", "0+1+0=01", "0+1+1=10", "1+0+0=01", "1+0+1=10", "1+1+0=10", "1+1+1=11", }; public static String lookup(char b1, char b2, char c) { String formula = String.format("%c+%c+%c=", b1, b2, c); for (String s : lookupTable) {   if (s.startsWith(formula)) { return s.substring(s.indexOf("=") + 1);   } } throw new IllegalArgumentException();   } public static String zeroPad(String s, int length) { while (s.length() < length) { s = "0" + s; } return s; } public static String add(String s1, String s2) { int length = Math.max(s1.length(), s2.length()); s1 = zeroPad(s1, length); s2 = zeroPad(s2, length); String result = ""; char carry = '0'; for (int i = length - 1; i >= 0; i--) { String columnResult = lookup(s1.charAt(i), s2.charAt(i), carry); result = columnResult.charAt(1) + result; carry = columnResult.charAt(0); } if (carry == '1') { result = carry + result; } return result; }   public static String multiply(String s1, String s2) { String result = ""; String zeroSuffix = ""; for (int i = s2.length() - 1; i >= 0; i--) { if (s2.charAt(i) == '1') { result = add(result, s1 + zeroSuffix); } zeroSuffix += "0"; } return result;} }```

i call in another class with in this way
Code Java:

```String proiz=null; int pBrojac=0; System.out.print(ArrayUtils.add(binaren, binaren2)); System.out.println(); System.out.print(ArrayUtils.zeroPad(proiz, pBrojac)); System.out.println(); System.out.print(ArrayUtils.multiply(binaren, binaren2));```

and the mistake is this

at proekt2.ArrayUtils.lookup(ArrayUtils.java:24)
at proekt2.Kraj.main(Kraj.java:188)
Java Result: 1
• March 23rd, 2011, 04:45 AM
JavaPF
Re: I need help
Hello Marijana.
Welcome to the Java Programming Forums.

Don't forget you need to have the binaren and binaren2 variables..

Code Java:

``` String proiz = null; int pBrojac = 0;   String binaren = "binaren"; String binaren2 = "binaren2";   System.out.print(ArrayUtils.add(binaren, binaren2)); System.out.println(); System.out.print(ArrayUtils.zeroPad(proiz, pBrojac)); System.out.println(); System.out.print(ArrayUtils.multiply(binaren, binaren2));```

Looking at your code, you are throwing the IllegalArgumentException() which would suggest there is a problem here:

Code Java:

``` public static String lookup(char b1, char b2, char c) { String formula = String.format("%c+%c+%c=", b1, b2, c); for (String s : lookupTable) {   if (s.startsWith(formula)) { return s.substring(s.indexOf("=") + 1);   } } throw new IllegalArgumentException();   }```
• March 26th, 2011, 04:07 AM
marijana_ristova
Re: I need help
yes, i know that there is the problem but u don`t know how to repair it:(