#Error explanation

24 messages · Page 1 of 1 (latest)

tawny summit
#

Can anyone explain why this happen?

        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;
            }
timber relicBOT
#

<@&987246399047479336> please have a look, thanks.

shrewd onyx
#

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[]

lilac mulch
#

in java, u can only assign something to variables

#

foo = ...

#

not to methods foo() =...

#

or to literals or anything else

#

only to variables

tawny summit
#

Oh yes, charAt is a function, I can not adjust it

lilac mulch
#

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

tawny summit
#

Oh i see

#

Thanks for you guys explanation

mint trout