JAVA: missing return statement

前端 未结 3 2018
旧时难觅i
旧时难觅i 2020-12-22 09:17

my main concern with this code as of right now is a missing return statement.

public class stringstuff{

    //using charAt    
    public static String Rev         


        
3条回答
  •  無奈伤痛
    2020-12-22 09:52

    Let's break down the keywords in your function header:

    Public - Any function has access to this function
    Static - This function does not operate on object instance variables and does not require an instance of this object to be created before it can be used
    String - this function will return a String
    ..name.. - the name of the function
    (params) - input for your function
    

    Now note that Java thinks this function will return a string. The compiler checks to see if there is a return statement of the proper type.

    Either use a void as the functio type and print the string inside of the function (as you' re doing now), or add the return statement and move the print to the place where the function is called from (as already suggested).

    HTH

提交回复
热议问题