Search code examples
javabluej

Actual and formal arguments lists differ in length error


The below is a binary calculator I have been making, but when I try to run it, I get a "actual and formal arguments lists differ in length" error, and I do not know how to fix it. I can't really be sure, but it looks like a problem with trying to pass two arrays to a different method to add the elements together. Thanks!

public static void binaryConvert1 (int x)
{


    int a = 0;
    int b = 0;
    int c = 0;
    int d = 0;
    int e = 0;
    int f = 0;
    int g = 0;
    int h = 0;


    double y = (int) x % 2;

    int array [ ] = new int [8];
    array [0] = h;
    array [1] = g;
    array [2] = f;
    array [3] = e;
    array [4] = d;
    array [5] = c;
    array [6] = b;
    array [7] = a;

    int length = array.length;

    for (int i = 0; i < length; i++)
    {
        System.out.print(array [ i ] + " ");
    }

    addBinary(array);
}

public static void binaryConvert2 (int z)
{


    int j = 0;
    int k = 0;
    int l = 0;
    int m = 0;
    int n = 0;
    int o = 0;
    int p = 0;
    int q = 0;


    double y = (int) z % 2;
int arraytwo [ ] = new int [8];
    arraytwo [0] = q;
    arraytwo [1] = p;
    arraytwo [2] = o;
    arraytwo [3] = n;
    arraytwo [4] = m;
    arraytwo [5] = l;
    arraytwo [6] = k;
    arraytwo [7] = j;

    int length = arraytwo.length;

    for (int i = 0; i < length; i++)
    {
        System.out.print(arraytwo [ i ] + " ");
    }

    addBinary(arraytwo);
}

private static void addBinary(int [] array, int [] arraytwo)
{
   int[] c = new int[8];
    for (int i = 0; i < 7; ++i) {
       c[i] = array[i] + arraytwo[i];

       if (c[0] == 2)
       {
           c [0] = 0;
           c [1] += 1;
        }
       if (c[1] == 2)
       {
           c [1] = 0;
           c [2] += 1;
        }
       if (c[2] == 2)
       {
           c [2] = 0;
           c [3] += 1;
        }
       if (c[3] == 2)
       {
           c [3] = 0;
           c [4] += 1;
        }
       if (c[4] == 2)
       {
           c [4] = 0;
           c [5] += 1;
        }
       if (c[5] == 2)
       {
           c [5] = 0;
           c [6] += 1;
        }
       if (c[6] == 2)
       {
           c [6] = 0;
           c [7] += 1;
        }
       if (c[7] == 2)
       {
           System.out.println("ERROR  -  FINAL NUMBER IS TOO LARGE.");
        }

        System.out.print("Added binary numbers:  " + c[i] + " ");
   }
}

Solution

  • You are making multiple calls to the addBinary() method. However, the method requires 2 arguments and in each call to the method, you are only providing 1 argument, hence the error.

    For example:

    addBinary(arraytwo);