下面是我一直在制作的二进制计算器,但是当我尝试运行它时,我得到一个"实际和正式的参数列表长度不同"错误,我不知道如何解决它。我无法确定,但尝试将两个数组传递给另一个方法以将元素添加到一起时,这似乎是一个问题。谢谢!
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] + " ");
}
}
答案 0 :(得分:0)
您正在多次调用addBinary()
方法。
但是,该方法需要2个参数,并且在每次调用该方法时,您只提供1个参数,因此会出错。
例如:
addBinary(arraytwo);