-
Switch Statement..return problem
Hi,
I am having a problem with a switch statement I have coded and have not found sample code to help me figure out exactly what I am doing wrong. The code is supposed to take a 2 dimensional array (String Array[4][7]) index i.e. rowNum and colNum and return a number between 1 and 28. The method requires an int return. When I pass the cursor over the end brace it says it is missing return statement. Here is the code... if you can see what I have done wrong please help!
public int findDayNum(int rowNum, int colNum){
switch (rowNum){
case 0:
if (colNum == 0) {return 1;}
else if (colNum == 1) {return 2;}
else if (colNum==2) {return 3;}
else if(colNum==3) {return 4;}
else if (colNum == 4) {return 5;}
else if (colNum == 5) {return 6;}
else if (colNum == 6) {return 7;}
break;
case 1:
if (colNum == 0) {return 8;}
else if (colNum == 1) {return 9;}
else if (colNum==2) {return 10;}
else if(colNum==3) {return 11;}
else if (colNum == 4) {return 12;}
else if (colNum == 5) {return 13;}
else if (colNum == 6) {return 14;}
break;
case 2:
if (colNum == 0) {return 15;}
else if (colNum == 1) {return 16;}
else if (colNum==2) {return 17;}
else if(colNum==3) {return 18;}
else if (colNum == 4) {return 19;}
else if (colNum == 5) {return 20;}
else if (colNum == 6) {return 21;}
break;
case 3:
if (colNum == 0) {return 22;}
else if (colNum == 1) {return 23;}
else if (colNum==2) {return 24;}
else if(colNum==3) {return 25;}
else if (colNum == 4) {return 26;}
else if (colNum == 5) {return 27;}
else if (colNum == 6) {return 28;}
break;
default: return -1;
}//end switch
}//end findDayNum
-
Think I have figured it out...
Hi,
Thanks for looking at this however, I see that the return statement, which must be the last statement ... cannot be the last statement in code like this. I have made the method a void proceedure and declared a variable to hold the answer as my solution to this problem.
Many thanks..
-
...
}//end switch
return -1;
// }//end findDayNum
-
Yes, I do realize it's been 5 years...BUT! I just HAD to register here and write this -
return rowNum*7 + colNum + 1;
instead of all that crap above
Similar Threads
-
By silencer01 in forum .NET
Replies: 1
Last Post: 08-11-2005, 09:00 AM
-
Replies: 3
Last Post: 08-01-2005, 08:05 PM
-
By Katovski in forum Database
Replies: 3
Last Post: 04-02-2003, 01:39 PM
-
By Rob Teixeira in forum .NET
Replies: 15
Last Post: 05-31-2002, 03:30 PM
-
By Ken Mui in forum ASP.NET
Replies: 1
Last Post: 10-06-2000, 05:18 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks