gpt4 book ai didi

Java错误: method in the type Finch is not applicable for the arguments (Scanner)"

转载 作者:行者123 更新时间:2023-12-02 00:02:16 25 4
gpt4 key购买 nike

这是我收到的错误:

The method saySomething(String) in the type Finch is not applicable 
for the arguments (Scanner)

代码:

Scanner user_input = new Scanner(System.in);

String userInput;
System.out.println("Enter your two words: ");
userInput = user_input.next();

myf.saySomething(user_input);

我假设 saySomething 方法不接受扫描仪输入,如何将输入转换为字符串?谢谢

最佳答案

选择相似变量名称的示例,这会导致代码困惑,如下所示:

您的 saySomething(String) 方法需要一个字符串作为参数,当前您正在传递扫描仪。

            Scanner user_input = new Scanner(System.in);
String userInput=user_input.next();
System.out.println("Enter your two words: ");
myf.saySomething(userInput);

为变量命名一些可以相互区分且有意义的内容。

Scanner userInput;
String words;

关于Java错误: method in the type Finch is not applicable for the arguments (Scanner)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14613264/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com