currLet = str.charAt(currPos);
AString
value can’t be assigned to achar
, they are different types, apples and orangesif (currLet = str.charAt(currPos + 1)) {
is actually an assignment (makecurrLet
equal to the value ofstr.charAt(currPos + 1)
)if (currLen > maxLen) {
–maxLen
is undefined- You never
return
anything from the method…
Try changing:
String currLet = "";
to something more likechar currLet="\0";
andString maxLet = "";
tochar maxLet="\0";
if (currLet = str.charAt(currPos + 1)) {
to something likeif (currLet == str.charAt(currPos + 1)) {
- Add
int maxLen = 0
to your variable declerations (may be underint maxCount = 0
)
Now, based on your example code, public int longestRep(String str) {
will need to be public static int longestRep(String str) {
in order for you to call from you main
method…