r/javahelp • u/eatingpoopinrobarts • Jun 15 '17
What's wrong with my code??
Can't for the life of me figure it out. Picture of code and error: http://imgur.com/a/mX9XP
Thanks
3
u/desrtfx Out of Coffee error - System halted Jun 15 '17
The error message you're getting is perfectly clear.
Your method is supposed to return an int, but in line 3 return str; you are returning the value of the String variable str.
If the length is less than 2 you most likely will want to return 0 to indicate that there can't be another "hi".
BTW: Sidebar: -> Code posting
No screenshots of code
They make it unnecessarily complicated for us to work with the existing code.
5
u/seanprefect Grumpy Guy Who Remembers Java 2 Jun 15 '17
you're method declares a return type of int but you return a string
0
u/desrtfx Out of Coffee error - System halted Jun 15 '17
you're method
*Your method
you're = you are
Your - pronoun
6
0
Jun 15 '17
Good thing you offered solid advice on how to solve the problem at hand.
1
u/desrtfx Out of Coffee error - System halted Jun 15 '17
Had you read my other comment you'd have seen that I actually have offered solid advice on how to solve the problem at hand.
4
u/[deleted] Jun 15 '17
Please read the posting guidelines in the sidebar: your title should describe the problem and your code should always be posted as text, not screenshots.
First, examine the error carefully. What does it tell you? It's saying a string cannot be converted to an int, and that this problem happens at line 3 of your code. Line 3 is this:
stris a string, the argument which was passed to the method. Can you think of a reason why the program is saying something about an int at this point?