Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

3 Visitor Messages

  1. hey, I want to ask me why this error occurs

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
    at proekt1.NewClass.main(NewClass.java:44)
    Java Result: 1

    there is my code


    package proekt1;
    public class NewClass{
    public static void main(String args[]){


    int a[]=new int[]{0,0,1,0};
    int b[]=new int[]{0,1,1,0};
    int S[]=new int [7];
    int c[][]=new int[4][4];
    int i,f,j,n,p,t;



    for(i=1;i<4;i++)
    {
    for(j=1;j<4;j++)
    {
    if(a[i]==1 && b[j]==1)//sporedba na cifrite
    {
    f=1;
    }
    else
    {
    f=0;
    }
    c[i][j]=f;
    }
    }



    System.out.print("Proizvodot na broevite "+a[0]+""+a[1]+""+a[2]+""+a[3]+" i "+b[0]+""+b[1]+""+b[2]+""+b[3]+" e:");//pecatenje na broevite
    for(i=1;i<=4;i++)//smestuvanje na dvata broja vo dvodimenzionalna niza
    {
    System.out.println();
    System.out.print(" ");
    for(n=0;n<i;n++)
    {
    System.out.print(" ");
    }
    for(j=0;j<4;j++)
    {
    System.out.print(c[i][j]+" ");
    }

    }

    S[7]=c[4][4];
    S[6]=(c[3][4]+c[4][3])%2;
    p=(c[3][4]+c[4][3]-S[6])/2;
    S[5]=(p+c[2][4]+c[3][3]+c[4][2])%2;// sobiranje po modul 2
    t=p;
    p=0;
    p=(t+c[2][4]+c[3][3]+c[4][2]-S[5])/2;
    S[4]=(p+c[1][4]+c[3][2]+c[2][3]+c[4][1])%2;
    t=p;
    p=0;
    p=(t+c[1][4]+c[3][2]+c[2][3]+c[4][1]-S[4])/2;
    S[3]=(p+c[1][3]+c[2][2]+c[3][1])%2;
    t=p;
    p=0;
    p=(t+c[1][3]+c[2][2]+c[3][1]-S[3])/2;
    S[2]=(p+c[1][2]+c[2][1])%2;
    t=p;
    p=0;
    p=(t+c[1][2]+c[2][1]-S[2])/2;
    S[1]=(p+c[1][1])%2;
    t=p;
    p=0;
    p=(t+c[1][1]-S[1])/2;
    S[0]=p;
    for(i=0;i<=7;i++)//pecatenje na proizvodot
    {
    System.out.print(S[i]+" ");
    }

    }
    }
  2. and i call in this way
    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));

    I do not know how to fix it and I need to be ready tomorrow
  3. hey, I am new in this forum and i have a big problem. i hope someone will help me..
    I need to multiply two float pointing binary number. i wrote something and it work ok if the main class and code is in the same class , f but when i call it from another main class occures this problem

    Exception in thread "main" java.lang.IllegalArgumentException
    at proekt2.ArrayUtils.lookup(ArrayUtils.java:24)
    at proekt2.ArrayUtils.add(ArrayUtils.java:40)
    at proekt2.Kraj.main(Kraj.java:188)
    Java Result: 1
    there is my code
    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;}}
Showing Visitor Messages 1 to 3 of 3
About marijana_ristova

Basic Information

Statistics


Total Posts
Total Posts
2
Posts Per Day
0.00
Visitor Messages
Total Messages
3
Most Recent Message
March 26th, 2011 05:30 AM
Total Thanks
Total Thanks
0
  • Thanked 0 Times in 0 Posts
General Information
Last Activity
April 28th, 2011 11:42 AM
Join Date
March 22nd, 2011