Java 错误,方法无法应用于给定类型

Java 错误,方法无法应用于给定类型,java,bluej,Java,Bluej,该代码应询问事故数量,确定五个地区中事故数量最少的地区,并打印事故数量和地区。我对java相当陌生,我遇到了这个错误。它说第四堂课家庭作业中的getNumAcidents方法不能应用于给定的类型;必需:双重查找:无参数原因:实际列表和正式列表长度不同。如何解决此问题 import java.util.*; public class fourthHomework { public static void main(String args[]) { double smallest = 0; doub

该代码应询问事故数量,确定五个地区中事故数量最少的地区,并打印事故数量和地区。我对java相当陌生,我遇到了这个错误。它说第四堂课家庭作业中的getNumAcidents方法不能应用于给定的类型;必需:双重查找:无参数原因:实际列表和正式列表长度不同。如何解决此问题

import java.util.*;
public class fourthHomework
{
public static void main(String args[]) {
double smallest = 0;
double north = getNumAccidents();
double south = getNumAccidents();
double east = getNumAccidents();
double west = getNumAccidents();
double central = getNumAccidents();

getNumAccidents(smallest);
findLowest(north, south, east, west, central, smallest);


}
public static double getNumAccidents(double smallest) {
System.out.println("Please enter all accidents as positive numbers.");
Scanner input = new Scanner(System.in);
System.out.print("Please enter the amount of accidents: ");
smallest = input.nextDouble();
}

public static void findLowest(double north, double south, double east, double west, double central, double smallest) {
System.out.println("The lowest amount of accidents this year was " +smallest);
if (north == smallest)
{
    System.out.println("The region that had the least amount of accidents was the north.");
}

if (south == smallest)
{
    System.out.println("The region that had the least amount of accidents was the south.");
}

if (east == smallest)
{
    System.out.println("The region that had the least amount of accidents was the east.");
}

if (west == smallest)
{
    System.out.println("The region that had the least amount of accidents was the west.");
}

if (central == smallest)
{
    System.out.println("The region that had the least amount of accidents was the central region.");
}
}
}

您的问题是因为在方法GetNumAcidents(最小双精度)中需要双精度作为参数。在声明double-north、south、east、west和central时,不为方法添加任何参数。您需要添加双倍,否则它将运行。另外,因为您说过该方法将返回一个double,所以您需要在该方法的末尾说

return smallest

让主要方法的开头显示:

public static void main(String args[]) {
    double smallest = 0.0;
    double north = getNumAccidents(smallest);
    double south = getNumAccidents(smallest);
    double east = getNumAccidents(smallest);
    double west = getNumAccidents(smallest);
    double central = getNumAccidents(smallest);
...
getNumAcidents
方法中,由于它被声明为double,因此需要返回一个double值:

...
smallest = input.nextDouble();
return smallest;
}

这不会完全修复程序,但它会帮助您在执行过程中解决问题。

方法
getnumacidents
需要一个参数。执行
double south=getNumAccidentd()
时,应该向它传递一个值,其他方向也是如此。另外,您似乎忘记了让该方法返回一个值。这里有很多问题,谢谢!当我运行它时,不管我输入了什么,它都会说最小的事故量是0。您对此有什么建议吗?@carrollsoccer5您可以查看main方法,其中显示getnumacidents(最小值);把它分配给最小的变量而不是等于零?@carrollsoccer5分配给最小的变量是这样的:
minimate=getnumacidents(minimate)而不是
getnumacidents(最小)。。。然后,当您运行程序时,无论您输入什么,您都不会将0视为最小的事故数(除非它是一个输入数)。您仍然需要修复
getNumAcidents
方法以请求5个区域输入(而不是6个),并将正确的最低值分配给最小值(变量名)。如何使其不请求6个?抱歉问了这么多问题,你帮了大忙。