我不知道什么是错的,但是我不能让这个方法返回我想要的字符。在“返回”一词下,我只是不断收到红线形式的错误。从方法中返回一个字符
这是我的方法。
public static char getOperator(String fileContent){
int checkAdd = fileContent.indexOf('+');
int checkMinus = fileContent.indexOf('-');
int checkMulti = fileContent.indexOf('*');
int checkDivi = fileContent.indexOf('/');
if (checkAdd != -1){
return char operator = fileContent.charAt(fileContent.indexOf('+'));
}
else if (checkMinus != -1) {
return char operator = fileContent.charAt(fileContent.indexOf('-'));
}
else if (checkMulti != -1) {
return char operator = fileContent.charAt(fileContent.indexOf('*'));
}
else if (checkDivi != -1){
return char operator = fileContent.charAt(fileContent.indexOf('/'));
}
return 0;
}
好的,对不起,我一直在蚀它在日食,并没有抓住这个问题。但是,现在ifs中的返回语句仍然会产生错误。我如何解决这个问题?
你的函数返回void '公共静态无效getOperator()' – Scony
公共静态无效getOperator(){} ...你期待它返回什么? – JoeC
代替退货。您目前正在返回一个不是字符的数字; '返回'';' –