I am learning to code with Java and started a little project.
I ran however into a problem which I cannot solved even though I tried everything from similar problems.
I have the below code:
import java.util.Scanner;
public class worldwarone {
public static void main(String[] args) {
Infantry firstalliedregiment = new Infantry();
firstalliedregiment.troops = 3500;
firstalliedregiment.equipement = "Excellent";
firstalliedregiment.morale = "High";
firstalliedregiment.name = "First Allied Regiment";
Infantry secondalliedregiment = new Infantry();
secondalliedregiment.troops = 4500;
secondalliedregiment.equipement = "Medium";
secondalliedregiment.morale = "Poor";
secondalliedregiment.name = "Second Allied Regiment";
Infantry firstcentralpowersregiment = new Infantry();
firstcentralpowersregiment.troops = 4000;
firstcentralpowersregiment.equipement = "Good";
firstcentralpowersregiment.morale = "High";
Infantry secondcentralpowersregiment = new Infantry();
secondcentralpowersregiment.troops = 6000;
secondcentralpowersregiment.equipement = "Good";
secondcentralpowersregiment.morale = "Medium";
Scanner input = new Scanner(System.in);
System.out.println("Select Regiment: ");
String yourregiment = input.nextLine();
if (yourregiment.equals("First Allied Regiment")); {
System.out.println("First Allied Regiment awaiting orders."); }
else if (yourregiment.equals("Second Allied Regiment"));
{ System.out.println("Second Allied Regiment awaiting orders."); }
else { System.out.println("No Regiment selected."); }
}
}
I get however the Syntax error on token "else", delete this token.
I am trying to compare two Strings that are the names of two Objects.
Aucun commentaire:
Enregistrer un commentaire