【发布时间】:2016-03-24 22:58:08
【问题描述】:
任何人都知道这个错误意味着什么:
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;
}
}
我该如何解决这个问题?
【问题讨论】:
-
看看
getLength的参数...然后看看你传递的参数(无)... -
你能解释一下这些论点吗?我有点迷路了
-
getLength(...)的目的是什么?它返回一个要求您输入的值。 -
如果您对如何调用方法感到困惑,我强烈建议您阅读一本好书或教程。当您掌握一门语言的基础知识时,Stack Overflow 非常适合解决特定问题,但它不是开始学习一门语言的好方法。
-
我尽可能地格式化了代码。好像有一个错误,然后有一个单独的代码块,但我不确定拆分在哪里。