#Error explanation
24 messages · Page 1 of 1 (latest)
Detected code, here are some useful tools:
String base_line = "_____";
for (int a : sol) {
for (int i = 0; i < base_line.length(); i += 1) {
if (a == 1) {
base_line.charAt(i) = ' * ';
}
i += 1;
}
<@&987246399047479336> please have a look, thanks.
a method call returns an rvalue, you can not assign to an rvalue
charAt returns the char at position i by value you can not assign a char to that char
it is like doing 'a' = '*'
not possible, it is like the linter says, you can only assign to variables and a method call is not a variable
Strings are also immutable so there is no method to change a char at an idex
you maybe want to use an char[]
(not sure that terminology is commonly known in the java world. so might confuse OP)
in java, u can only assign something to variables
foo = ...
not to methods foo() =...
or to literals or anything else
only to variables
Oh yes, charAt is a function, I can not adjust it
in ur case ur looking for sth like setChar(...). but such a method doesnt exist for strings
for building ur hangman string it would be better if u dont use String but StringBuilder as ur base instead
that one also supports changing chars easily
alternatively a char[] would also work
but printing it is then for example not as convenient
or checking it against the solution
You probably confused that with array[i] = 'o' because that's possible its not a method