+ 2
Explain pls the output of this code
public static void main(String[] args){ char[] test = {'a', 'b', 'j', 'l', 'm'}; System.out.println((char)((--test[4])-1)); The output is k
5 Antworten
+ 3
first it gets test[4] --> m
then you need to understand that char is just an encoded number in ASCII http://www.torsten-horn.de/techdocs/ascii.htm
I used that in my code to tell what letters there are: https://code.sololearn.com/cRL3AllAR3N9/#
--test[4] --> the letter 'm' in ASCII is 109. Decreased to 108 and written back into the char array because of '--', the array becomes {'a', 'b', 'j', 'l', 'l'} and the letter for further calculation is the second 'l'
'l' - 1 --> 108 - 1 --> 107
(char) 107 --> 'k'
.
nonzyro no offense but this proves you are wrong with your 'decreased the pointer, pointing it at memory containing 'l'': https://code.sololearn.com/cXbc3Hj0o2sP/#java
+ 2
Johann Leis
Sorry, I just reread the whole thread. :(
I must've misread the question (when I saw "(char)" I saw "(char*)" and assumed it was a cast and pointer arithmetic, I didn't even notice it was a Java question) I admit I only skimmed your code and probably misread that too. I have no idea if you've edited it since, but there's nothing wrong with it whatsoever. I remember thinking, "Why's he using Java?" Anyway, since my answer's on top and very misleading, I'll delete it. I'll delete my other post too, since your code was isn't wrong.
+ 2
nonzyro no problem; proves you're human😉
i'll delete my complains too
+ 1