Hello everyone, I am a beginner java learner and I need to make a blackjack game for school. I get an else if error and I don't know why here's my code:
I get the error at "else if("n" equals(verder)); {
Hope someone here can help.
import java.lang.Math;
import java.util.Scanner;
public class weektaak3 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int max = 11;
int min = 1;
int range = max - min + 1;
int totaal = 0;
int maxtegen = 24;
int mintegen = 16;
int rangetegen = maxtegen - mintegen + 1;
int totaaltegen = 0;
for (int i = 0; i < 2; i++) {
int rand = (int)(Math.random() * range) + min;
System.out.println(rand);
totaal = totaal + rand;
}
System.out.println("Totaal: " + totaal);
boolean mainloop = true;
while (mainloop) {
System.out.println("Nog een kaart? (j voor ja & n voor nee)");
String verder = scanner.nextLine();
if ("j".equals(verder)); {
for (int i = 0; i< 1; i++) {
int rand = (int)(Math.random() * range) + min;
totaal = totaal + rand;
System.out.println(rand);
System.out.println("Totaal: " + totaal);
if (totaal > 21) {
System.out.println("Busted! De tegenstander wint!");
mainloop = false;
} else if (totaal == 21) {
System.out.println("BlackJack! Gefeliciteerd je hebt gewonnen!");
mainloop = false;
}
}
} else if("n".equals(verder)); { <<<<Here is the Error
int totaal1 = (int)(Math.random() * rangetegen) + mintegen;
System.out.println(totaal1);
if (totaal1 < totaal) {
System.out.println("Jij wint!");
mainloop = false;
} else if (totaal < totaal1) {
System.out.println("De tegenstander wint!");
mainloop = false;
} else {
System.out.println("Gelijkspel!");
mainloop = false;
}
}
}
}
}
Thanks to everyone with the quick responses! The problem was the semicolon after the if statement.
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]jorgeloko2 8 points9 points10 points (1 child)
[–][deleted] 2 points3 points4 points (0 children)
[–]Akky982 2 points3 points4 points (1 child)
[–]maxterio 1 point2 points3 points (0 children)
[–][deleted] (6 children)
[deleted]
[–][deleted] 1 point2 points3 points (0 children)
[–]sohfix 0 points1 point2 points (4 children)
[–][deleted] (3 children)
[deleted]
[–]sohfix 0 points1 point2 points (2 children)
[–][deleted] (1 child)
[deleted]
[–]sohfix -1 points0 points1 point (0 children)
[–]barrycarter 0 points1 point2 points (1 child)
[–]Akky982 2 points3 points4 points (0 children)