lundi 17 juin 2019

I get a syntax error on else when I run my code

Whenever I try to execute my code, I get an error saying I should remove my second "else" even though there are two "if"s.

I've tried removing the else, but then it outputs both "You guessed right!" and "Man you are dumb, I said inbetween 1 and 10!"

    int x = 6;
    if (x < 10) {
        if (x == 6) {
            System.out.println("You guessed right!");
        } else {
            System.out.println("You guessed wrong.");
    } else {
            System.out.println("Man you are dumb, I said inbetween 1 and 10!");
    }

I expected it to output "You guessed right!" but insted I get this message in output.

Exception in thread "main" java.lang.Error: Unresolved compilation problem: Syntax error on token "else", delete this token

at aa.test.main(test.java:20)

Aucun commentaire:

Enregistrer un commentaire