#trying to exctract the middle character from a text string
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.
U want middle character, not position?? But you got the position so what's the problem??
U can get the character at that position
text.charAt(x)
umm when i lets say type hello i get number 3
but i want the "l" to outprint
@stoic musk
yeah, u gotta use text.charAt(x)
whats unclear to u, after getting the explanation?
if u need more hands-on help, u have to share ur code
where is the main method?
ah
u want ur method to return a char
but u wrote int
so java converts the char to its ascii index
i see thats why i get like 97 when i typ aaaa
yes
now the return statement screams at me insted
it wants me to change my method to a boolean?
no
u have to understand the error messages and ur code
now u wrote that ur method must return a char, as u wanted
however
u return a boolean now in line 30
which represents the case when u have entered text with an odd length
u return the mid char if the user entered an even text
but return false if the user entered an odd text
yes, i just wanted to see if that first statement worked
okay. but to make java happy, u must return a char in all cases
so return some char instead
okey
or throw new AssertionError("TODO");
theres neither a need for a variable
nor do chars take ints
u can write a char by using '...'
instead of "..." for strings
okay. quick tip about debugging. add a System.out.println("Mid is: " + mid); to ur code
and tell us what it says
ull notice the issue immediately after doing that
in the main?
in ur middle method
where u compute int mid
u have to inspect ur method with prints to figure out whats going wrong
stop just staring at ur code. u wont find the bugs like that
u gotta inspect what ur variables are
print them out
thats what u think
not what the code says
i know what u wanted to do. but apparently it doesnt work yet
so u have to find the bug
and the easiest way to do that is by printing out ur variables
cause u will suddenly notice that they are not what u thought they are
and thats how u find the bugs
just put the print in there please and show me what it says
println not print please
anyways. so whats the matter now? l is the middle of hell
what did u want to get instead?
okay
thats bc u didnt think about indices starting at 0
let me show u:
abcd
0123
length of abcd is 4
ohhh i seee
hahaha
my man! now i got more problems to fix but i will try that on my own first
thx for all the help
❤️
ur welcome, good luck 🙂
tyty

