Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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;
    	}
    }

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    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());
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •