JAVA:缺少返回语句 [英] JAVA: missing return statement
本文介绍了JAVA:缺少返回语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
到目前为止,我对这段代码的主要担忧是缺少 return 语句.
my main concern with this code as of right now is a missing return statement.
public class stringstuff{
//using charAt
public static String ReverseF(String n){
String finalstring = "";
int len = n.length();
for (int i = 0; (i < n.length()); i++){
finalstring += (n.charAt(len - i - 1));
}
System.out.println(finalstring);
}
public static void main(String[]args){
ReverseF("Hello");
}
}
使用此代码我只会收到错误:
Using this code I only get the error:
stringstuff.java:11: missing return statement
}
^
1 error
如果我切换 System.out.println 返回,我不会收到任何错误,但我也不会得到 ReverseF("Hello") 的答案;
If I switch the System.out.println to return, I don't get any errors but I also don't get an answer for ReverseF("Hello");
推荐答案
你有两个选择:要么写
public static void /* not String */ ReverseF(String n){
或者在ReverseF
中写return finalString
并使用
public static void main(String[]args){
System.out.println(ReverseF("Hello"));
}
这篇关于JAVA:缺少返回语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文