gpt4 book ai didi

java - 如何使用方法修复 "actual and formal argument lists differ in length"?

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

我正在使用方法进行分配,但无法通过 getBidAmounts 方法。我不断收到此类错误:

必需:int[],int 找到:int[] 原因:实际参数列表和形式参数列表长度不同

public static void main (String[] args) {

double budget = getBudget();
final double MIN_BID_AMOUNT = 0;

final int MIN_NUM_BIDS = 0;
final int MAX_NUM_BIDS = 100;
int numBids = getNumBids(MIN_NUM_BIDS, MAX_NUM_BIDS);
int[] bids = new int[numBids];
getBidAmounts(bids);
}

public static void getBidAmounts (int[] bidAmounts, int minBidAmount) {
for (int i = 0; i < bidAmounts.length; i++) {
do {
bidAmounts[i] = Integer.parseInt(JOptionPane.showInputDialog("Enter the Amount of Bid #" + (i+1) + ": "));
if (bidAmounts[i] <= minBidAmount)
{
JOptionPane.showMessageDialog(null, "Enter a Valid Bid Amount Above" + minBidAmount + ".");
}
} while (bidAmounts[i] <= minBidAmount);
}
}

这应该允许用户将内容输入到数组中。

最佳答案

当您调用getBidAmounts(bids);时您只提供一个参数,而

public static void getBidAmounts (int[] bidAmounts, int minBidAmount)需要两个参数。

所以,改变 getBidAmounts(bids);getBidAmounts(bids, <强> MIN_NUM_BIDS ); .

在这里,MIN_NUM_BIDS将代表参数 minBidAmount (第二个)里面getBidAmounts方法。

关于java - 如何使用方法修复 "actual and formal argument lists differ in length"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55785945/

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