任何人都知道此错误的含义:
RectangleArea.java:21: error: method getLength in class RectangleArea cannot be applied to given types;
length = getLength();
^
required: double,Scanner
found: no arguments
reason: actual and formal argument lists differ in length
import java.util.Scanner;
public class RectangleArea
{
public static void main (String [] args)
{
Scanner keyboard = new Scanner (System.in);
double length, // The rectangle's length
width, // The rectangle's width\
area; // The rectangle's area
welcomeBanner ();
// Get the rectangle's length from the user.
length = getLength();
}
static void getLength(double aLength, Scanner aKeyboard)
{
System.out.print("Enter the rectangle's length: ");
aLength = aKeyboard.nextDouble ();
System.out.println("");
return aLength;
}
}
我该如何解决这个问题?
答案 0 :(得分:0)
getLength
是一种无效方法。如果您想要返回一些内容,则需要将void
替换为数据类型double
。您还需要确保传递正确的参数类型和正确数量的参数。
答案 1 :(得分:0)
方法getLength()
:
double aLength
和Scanner aKeyboard
。double
的长度,但您不会从方法void
返回任何内容(getLength()
)。如果您尝试这样做怎么办:
static double getLength()
{
Scanner keyboard = new Scanner (System.in);
double aLength;
System.out.print("Enter the rectangle's length: ");
length = keyboard.nextDouble ();
System.out.println("");
return length;
}
此外,您应该从keyboard
方法中删除变量main()
。