okay - I've about had it. In order to thwart my impending self destruction....would someone please post what the code would look like if you have a two dimensional array....like...for instance....
{ {"111111111", "222222222", "333333333", "444444444", "555555555"}, {"Mary Lou Buford", "Billy Bob Jackson", "John Doe", "Jane Doe", "Sally Jo Pitkin"} };
and you want to pass a social security number (such as the ones listed above) to the function and return the corresponding employees names. Please make it as plain as possible.... Thanks in advance. EB
Ernest Friedman-Hill
,
author and iconoclast
staff
public class TestEmployee { String [] [] empArray; public void employee () { String [] [] empArray =
{ {"111111111", "222222222", "333333333", "444444444", "555555555"}, {"Mary Lou Buford", "Billy Bob Jackson", "John Doe", "Jane Doe", "Sally Jo Pitkin"} }; } String SSNToName(String ssn) { for (int i=0; i<empArray.length; ++i) if (empArray[0][i].equals(ssn)) return empArray [1][i]; } } So close...and yet so far..... When I try to compile this I get "missing return statement" What now? EB
Ernest Friedman-Hill
,
author and iconoclast
staff
It's possible to reach the end of the function without finding an answer. In my example code, I show one possible thing you can do at that point, and in a comment, listed two others. You've omitted all three, hence the message. You have to do something if the SSN isn't found.
That's because you're only returning in the event that the if statement tests true. What if it's never true? This thought worries the compiler quite a bit and it complains about it. Plus, the compiler is extra worried that the for loop might never run if the entry condition is never true. Outside of the for loop, you could just add a statement that returns some value that indicates that the search failed, or you could throw an exception. Both solutions should appease the compiler.
Never mind...you can call off the suicide watch... Please understand how fried my feeble brain is. Thank you so much for your help. Sure to be back, EB
Post by:autobot
Would anybody like some fudge? I made it an hour ago. And it goes well with a tiny ad ...
a bit of art, as a gift, that will fit in a stocking