-1
public static int countPopular(int count0, int count1, int count2) {
    int result;
    if (count0 > count1 && count0 > count2) {
        result = 0;

    }

    else if (count1 > count0 && count1 > count2) {
        result = 1;
    }

    else if (count2 > count0 && count2 > count1) {
        result = 2;
    }
    else {
        result = -1;
    }
    return result;
}

Having issues figuring out where I am missing parenthesis in this multi-block statement.

Message: '}' at column 7 should be on the same line as the next part of a multi-block statement (one that directly contains multiple blocks: if/else-if/else, do/while or try/catch/finally).


Line: 28    Message: '}' at column 7 should be on the same line as the next part of a multi-block statement (one that directly contains multiple blocks: if/else-if/else, do/while or try/catch/finally).


Line: 32    Message: '}' at column 7 should be on the same line as the next part of a multi-block statement

These are the error messages I am receiving.

Fraction
  • 11,668
  • 5
  • 28
  • 48
  • Please explain what error message or behaviour makes you think the parentheses are wrong. – tgdavies Oct 21 '21 at 22:22
  • 1
    It's asking for you to put the if else/else statement onto the same line as the closing bracket from the last statement. – Nemo9703 Oct 21 '21 at 22:25
  • 3
    Those aren't errors. It is Checkstyle telling you that your code doesn't comply with the conventions it should be following. – Ivar Oct 21 '21 at 22:27
  • You should be aware that it's not a requirement of the language; it's just a style that some people (not me) like. – user16632363 Oct 21 '21 at 23:37

1 Answers1

0

Like This:

public static int countPopular(int count0, int count1, int count2) {
    int result;
    if (count0 > count1 && count0 > count2) {
        result = 0;
    }else if (count1 > count0 && count1 > count2) {
        result = 1;
    }else if (count2 > count0 && count2 > count1) {
        result = 2;
    }else {
        result = -1;
    }
    return result;
}
op_
  • 92
  • 7