【发布时间】:2013-05-15 20:09:31
【问题描述】:
这是我的问题:
我有一个方法,其中一个参数是 Scanner cons,如下所示:
public void buyIngredients (Scanner cons){}
它有效,但主要是错误:
import java.util.Scanner;
public class Main{
public static void main(String [] args){
Hero h = new Hero();
Scanner scan = new Scanner(System.in);
int value = scan.nextInt();
System.out.println(h.buyIngredients(value));
错误是这样的:
Main.java:11: error: method buyIngredients in class Hero cannot be applied to given types;
System.out.println(h.buyIngredients(value));
^
required: Scanner
found: int
reason: actual argument int cannot be converted to Scanner by method invocation conversion
【问题讨论】:
-
该错误准确地说明了问题所在。它需要
Scanner,而您提供的是int。请阅读错误文本。
标签: java methods parameters java.util.scanner