I'm having a little problem with getting my if statement to work. The scenario is that the user should be able enter 1 if they want British teams or 2 if they want American teams. Once they pick a region a list of teams will appear and they enter the number of team and the information of that team should print out but for some reason it just keeps looping and asks to enter a team. I have simplified my code slightly for here otherwise it would be too big.
ArrayList<STeam> teams = rCSV.readSTeams("sports-teams.csv");
Scanner UInput = new Scanner(System.in);
System.out.println("Enter 1 for British teams or 2 for American teams");
int choice = UInput.nextInt();
for (STeams st1 : teams) {
if (choice == 1) {
System.out.println("Choose: 1. London FC");
int choice2 = UInput.nextInt();
{
if (choice2 == 1) {
if (st1.getName().equals("London FC")) {
System.out.println(st1);
}
}
}
}
else if (choice == 2) {
System.out.println("test");
}
}
Apologies if this is extremely messy. I have a separate class that reads the file and a separate class for the sports teams and I know these work as I have done something similar like this but with only using 1 if statement within another instead of 2.
Aucun commentaire:
Enregistrer un commentaire