#simple java question

1 messages · Page 1 of 1 (latest)

worthy krakenBOT
#

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

hollow pilot
#

Check your (, ) pairings...

#

And you should really use && there. There's no benefit to the lack of short-circuiting since the second term has no side-effects.

real sinew
#

ok

real sinew
hollow pilot
#

every ( should have a matching ) (and vice versa)

You only have a few places to check. The if statement is the only complex one.

real sinew
hollow pilot
#

Excellent that's the bracketing fixed. The 'incompatible types' is down to the fact that str.charAt(n) returns a char and "e" is a string. use 'e' instead (a char literal)

real sinew
#

in python "" and '' is the same

hollow pilot
#
  • "e" is a literal String - use .equals(...) to compare strings.
  • 'e' is a literal char - use == to compare chars.
#

A char is a primitive (a fixed-size type). a String is a reference type allowing Strings of varying lengths. Unlike Python ' is not used to represent strings.

real sinew
#

instead of doing == 'e'

#

can i do this?

#

because in the future i might have to compare string to string @hollow pilot

hollow pilot
#

The substring is more expensive (creating a new object).

hollow pilot
#

No because substring produces a String and 'e' is a char.

#

And note that the substring will be everything at and after position i + 3