Code:
public void setStats() {
boolean done = false;
int temp[] = new int[6];
do {
System.out.println("Rolling the dice...");
for (int i = 0; i < 6; i++) {
temp[i] = rollStat();
}
System.out.println("The numbers rolled:");
for (int i = 0; i < 6; i++) {
System.out.println(temp[i]);
}
System.out.println("Do you want to keep these?(Y or N)");
Scanner in = new Scanner(System.in);
String answer = in.next();
if (answer == "Y" || answer == "y") {
done = true;
} else if (answer == "N" || answer == "n"){
done = false;
}
} while (done == false);
}
setStats is called from main(). rollStats is a simple RNG that gives a number between 3 and 18.
The issue is that if you answer yes to the question, "Y" or "y," it sets
done to
true but it doesn't break the loop. I've also tried throwing a
break statement at it. No joy.