我正在尝试调用方法readAndFill();在我的主要方法中。我收到一条错误消息,提示“ readAndFill无法应用于给定类型。readAndFill是一种将数字放入数组的方法。
我已重命名该方法,将readAndFill(double [] array,int numOfNumbers)代替了readAndFill();。
package program9;
import java.util.Scanner;
import java.util.Arrays;
public class Program9 {
static void readAndFill(double[]array, int numOfNumbers) {
Scanner keyboard = new Scanner(System.in);
for(int i=0;i < numOfNumbers; i++){
System.out.print("Enter a number: ");
array[i] = keyboard.nextDouble();
}
}
public static void main(String[] args) {
int numOfNumbers;
Scanner keyboard = new Scanner(System.in);
double arrayNumbers;
System.out.print("How many numbers will be read in the array?:
");
numOfNumbers = keyboard.nextInt();
double[] array = new double[numOfNumbers];
readAndFill();
}
static void readAndFill(double[]array, int numOfNumbers) {
Scanner keyboard = new Scanner(System.in);
for(int i=0;i < numOfNumbers; i++){
System.out.print("Enter a number: ");
array[i] = keyboard.nextDouble();
}
}
答案 0 :(得分:0)
readAndFill方法需要两个参数。 用下面的内容替换main()中的方法调用。
readAndFill(array,numOfNumbers);
答案 1 :(得分:0)
以这种方式readAndFill(array , numOfNumbers);