这是我的问题:
我有一种方法,其中一个参数是 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