Hello I'm fairly new to java and I had troubles in a little test game. So this is just a part of the code, I want that the user can repeat the part as often as he like with an while operater.
The code is here:
else if (a == 6){
boolean InGame = true;
while ( InGame );
System.out.println("Glückspiel: Wer näher an der zufälligen Zahl ist gewinnt! 1-100");
System.out.println("Spieler Eins");
double playerOne = scan.nextDouble();
System.out.println("Spieler Zwei");
double playerTwo = scan.nextDouble();
double randomValue = Math.random() * 100.0;
// Math.abs
double spacingOne = Math.abs(playerOne - randomValue);
double spacingTwo = Math.abs(playerTwo - randomValue);
System.out.println("Die Random Zahl war " + randomValue);
if (spacingOne < spacingTwo) {
System.out.println("Spieler Eins hat gewonnen!");
}
if (spacingOne > spacingTwo) {
System.out.println("Spieler Zwei hat gewonnen!");
}
if (spacingOne == spacingTwo) {
System.out.println("Unentschieden!");
}
System.out.println("Wenn du nochmal spielen willst schreibe 'ja' wenn nicht 'nein'");
String PlayAgain = scan.nextLine();
if (PlayAgain == "nein");
boolean inGame = false;
Well I have never worked alot with booleans due to me being new in java. Would nice if you could help me out.
Aucun commentaire:
Enregistrer un commentaire