I am in need of help trying to figure out this java program. My program will ask the user to enter a sentence then another word. Then it will ask the user to pick a number and that will tell the user what character is in that position. In the main method the program puts the string into an array but i am suppose to make a new method to find out what character is in the position they asked for. I have been using bluej for where i do my programming. Any help will be much appreciated. thank you very much. Here is my program i tried to use a .java file to attach but it wont let me.
You didn't quite get the code tags right, but don't worry; I have sorted them out. You can find out about the tags here.
Your method says it returns a char but you are returning a char array from inside the loop. That won't work.
By the code comments, I guess you aren't allowed to just call
I found this the most frustrating part of one of my CS courses back in the day (wow, saying that makes me feel old...). Why not just use the libraries you have to work with? Makes no sense...[/rant]
Anyway, to the problem at hand. As Campbell pointed out, you are trying to return a char inside the loop when your method declares (correctly) that it is returning a char. Hint: you passed in pos. What should you do with it?
One other thing I noticed is here:
The first call should be using charSentence, no?
It's also generally (arguably?) not a good idea to reassign variables like that. It's quite easy to run into trouble with reasoning about the state of things in more complicated programs when you let variables mutate like that. It's better to name your variables more precisely, or eliminate them altogether if you can inline the call.
She still doesn't approve of my superhero lifestyle. Or this shameless plug: