Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-04-2012, 03:58 AM   PM User | #1
vindeath
New to the CF scene

 
Join Date: Oct 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
vindeath is an unknown quantity at this point
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;
	}
}
vindeath is offline   Reply With Quote
Old 10-04-2012, 04:55 AM   PM User | #2
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,220
Thanks: 4
Thanked 80 Times in 79 Posts
Spookster will become famous soon enough
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
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Reply

Bookmarks

Tags
if else, if statements, java, method, return

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:50 PM.


Advertisement
Log in to turn off these ads.