Forums Register Login

Help with error " The method length() is undefined "

+Pie Number of slices to send: Send
I am practicing using CodingBat.com
http://codingbat.com/prob/p163411

I'm receiving the error that the length() method is undefined.  When I put it in Eclipse this works fine so I'm not sure why it's not working on CodingBat.com.  



But this works in Eclipse



+Pie Number of slices to send: Send
I think It suppose to be I don't know what exactly you want to do but did you notice what happens when String str = "A"; Or str = ""; ?
+Pie Number of slices to send: Send
 

Ganesh Patekar wrote:I think It suppose to be I don't know what exactly you want to do but did you notice what happens when String str = "A"; Or str = ""; ?



I wasn't clear in my message.  The problem currently being flagged is just the length() in .  So I took it to Eclipse to try and it works fine.   It prints out "He".
+Pie Number of slices to send: Send
Yes second example will work for sure, I was talking about first example which has else part.
+Pie Number of slices to send: Send
No, it was mentioned already, that problem is in line 9
in between the parenthesis you forgot to add references on which you're calling length() methods.
+Pie Number of slices to send: Send
Okay guys!  Thank you.  
+Pie Number of slices to send: Send
You're welcome
+Pie Number of slices to send: Send
That's a neat site, never saw it before.

The ternary operator is my sonic screwdriver:
+Pie Number of slices to send: Send
And need to consider checking if str isn't null before you invoke length() method or ensure outside the method that passed str isn't null and handle it appropriately otherwise.
It's a tiny ad. At least, that's what she said.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2925 times.
Similar Threads
Need help to remove duplicate from a string using recursion
adding commas as thousands separators recursively
How to validate Text field in java.It should accept only numric value.
Get middle initial
Need help to cut out a portion of string using recursion
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 00:25:23.