CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Java and JSP (http://www.codingforums.com/forumdisplay.php?f=54)
-   -   Java return statement problem. (http://www.codingforums.com/showthread.php?t=275096)

vindeath 10-04-2012 03:58 AM

Java return statement problem.
 
Hello there :)

I have a question about the return statement... I'm not getting anything when I run my code. I should get answers like Winter, Fall, Spring, Summer but my return is not working?

Thanks for the help. :)

Here is my code:

Code:

       
public static void main (String[] args){
       
        season(11, 15);

}
       
public static String season(int month, int day){
        String result = "";
               
        if((month == 12 && day >=16) || (month <= 3 && day <=15))
                result += "Winter";
        else if ((month >=9 && day >=16) || (month <=12 && day <=15))
                result += "Fall";
        else if ((month >=6 && day >=16) || (month <=9 && day <=15))
                result += "Summer";                       
        else if ((month >=3 && day >=16) || (month <=6 && day <=15))
                result += "Spring";
        return result;
        }
}


Spookster 10-04-2012 04:55 AM

You aren't seeing anything because you aren't doing anything with the returned value. The return statement just returns the value of the defined type to the caller of that method. In any language such as Java/C/C++ that supports a "return" statement, in order to use the returned value you would need to either "assign" that return value to a variable and then use it or simply make that method call where you need the value.

i.e.
variable = methodCall();
print(variable);

or

print(methodCall());


All times are GMT +1. The time now is 07:31 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.