samedi 16 octobre 2021

If else if statement to check if true

Im trying to type a code to check if a statement has been fulfulled, if so I'm required to display Yes on the screen. When I add brackets at the end it comes up with a message ' not a statement ' and underliness the whole line. Although when I dont add a bracket at the end it says ')' required. This is only the part of the code which isn't working, before that I have an if and it's working fine. Any ideas how to solve that?

double a1 = 10.0, a2 = 1.0;
        if ((a1 > a2 && a1 % 2 == 0 && a2 % 2 == 0)) {
            System.out.println("yes");
        } else if (a1 % a2 == 0 || a2 % a1 == 0) {
            System.out.println("yes");
        } else (a1 + a2 > a1 * a2 && (a1 % a2 == 0)) {
            System.out.println("yes");

Thanks

Aucun commentaire:

Enregistrer un commentaire