gpt4 book ai didi

java - 实际和形式参数列表长度不同错误

转载 作者:行者123 更新时间:2023-12-02 04:43:21 26 4
gpt4 key购买 nike

下面是我一直在制作的二进制计算器,但是当我尝试运行它时,出现“实际和形式参数列表的长度不同”错误,我不知道如何修复它。我真的不能确定,但​​是尝试将两个数组传递给不同的方法以将元素加在一起看起来是个问题。谢谢!

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] + " ");
}
}

最佳答案

您正在多次调用 addBinary() 方法。但是,该方法需要 2 个参数,并且在每次调用该方法时,您只提供 1 个参数,因此会出现错误。

例如:

addBinary(arraytwo);

关于java - 实际和形式参数列表长度不同错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35495674/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com