mardi 2 février 2021

"Syntax error on token "else", delete this token" (Java)

so I'm getting error in line 37 with the else if, and I don't have any idea why this is happening. The IDE says: "Syntax error on token "else", delete this token". Thanks.

package jogo;

import java.util.Scanner;
import java.util.Random;

public class Main 
{
    public static void main(String[] args)
    {   
     Scanner in = new Scanner(System.in);
     Random rand = new Random();
     String name;
     System.out.println("Welcome to the game! Enter your name.");
     name = in.nextLine();
     System.out.println("Welcome " +name);
     System.out.println("Which direction you will walk? ( W, A, S D )");
     String comando = in.nextLine();
     
     if(comando.equals("W"));
        System.out.println("You decided to walk through the vast forest.");
        System.out.println("And suddenly a goblin appeared, what are you going to do? ( A = Attack and C = Run )");
        comando = in.nextLine();
        if(comando.equals("A"));
            if(rand.nextInt(100) <= 75)
        {
            System.out.println("You won the battle.");
        }
        else
        {
            System.out.println("You lost the battle.");
            {       
            else if(comando.equals("C")); 
            System.out.println("You ran away from the battle.");
            }   
        }
    }
}   

Aucun commentaire:

Enregistrer un commentaire