方法无法应用于java中的给定类型错误
我不明白它在说什么是错的。该程序的目的是获取在main中输入的字符串,并通过scrambleMessage()函数运行该字符串以向上更改字母。我通过逐个字符地运行字符串来运行它,使每个字符都是相应的数字,然后重新生成一个字符。不确定发生了什么导致我出现此错误。因为您的方法无法应用于java中的给定类型错误,java,function,methods,compiler-errors,Java,Function,Methods,Compiler Errors,我不明白它在说什么是错的。该程序的目的是获取在main中输入的字符串,并通过scrambleMessage()函数运行该字符串以向上更改字母。我通过逐个字符地运行字符串来运行它,使每个字符都是相应的数字,然后重新生成一个字符。不确定发生了什么导致我出现此错误。因为您的扰码消息(char c,int x)接受2个参数。您应该传递char和int。因为您没有使用int参数,请删除它 : error: method scrambleMessage in class main cannot be app
扰码消息(char c,int x)
接受2个参数。您应该传递char和int。因为您没有使用int参数,请删除它
: error: method scrambleMessage in class main cannot be applied to given types;
scramble += scrambleMessage(input.charAt(i));
^
你也应该改变这一行
public static char scrambleMessage( char c)
{
int charc = c;
if (!Character.isLetter(c))
return c;
charc = (charc * (charc - 1))/(charc + (charc - 1)) + 5;
return (char)charc;
}
到
因为在使用局部变量之前应该初始化它们,并且应该避免null错误,所以您可以说:
类型main中的方法消息(char,int)不适用于参数(char)
,
您需要传递char和int,只需传递一个参数。
或编辑
到
我想你还有另外一个错误:
public static char scrambleMessage( char c)
您必须更改此行:
The local variable scramble may not have been initialized
到
所以我修正了这个问题并编译了它,但是现在不管我在第一个字符中输入什么字符串,它总是“null”。它是如何计算的?更改字符串输入,置乱=null;要输入字符串,请加扰=”;
String input, scramble = "";
public static char scrambleMessage( char c, int x)
public static char scrambleMessage( char c)
The local variable scramble may not have been initialized
String input, scramble ;
String input, scramble = "";