JAVA:缺少退货声明 [英] JAVA: missing return statement
本文介绍了JAVA:缺少退货声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我现在对此代码的主要关注是缺少返回语句。
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的答案(你好);
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
中返回finalString
or write return finalString
in ReverseF
and use
public static void main(String[]args){
System.out.println(ReverseF("Hello"));
}
这篇关于JAVA:缺少退货声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文