Hallo liebe Leute,
da ich noch Anfängerin bin, bekomme ich keine richtige Schleife hin.
Ich möchte das mich mein Programm am Ende fragt, ob ich nochmal spielen will und ich dann mit ja oder nein antworten kann.
Ich bedanke mich im voraus.
da ich noch Anfängerin bin, bekomme ich keine richtige Schleife hin.
Ich möchte das mich mein Programm am Ende fragt, ob ich nochmal spielen will und ich dann mit ja oder nein antworten kann.
Ich bedanke mich im voraus.
Java:
import java.util.Scanner;
public class schnickschnackschnuck {
public static void main(String[] args) {
int schere = 1;
int stein = 2;
int papier = 3;
double pcwahl;
int spielerwahl;
@SuppressWarnings("resource")
Scanner Scanner = new Scanner(System.in);
do {
pcwahl = (int) (Math.random() * 3);
System.out.println("Der Computer hat seine Wahl getroffen");
System.out.println("---------------------------------");
System.out.println("Du bist an der Reihe wähle die \n 1 = Schere \2 = Stein \n 3 = Papier");
System.out.println("---------------------------------");
spielerwahl = Scanner.nextInt();
if (spielerwahl == schere) {
if (spielerwahl == pcwahl) {
System.out.println("Keiner Gewinnt");
System.out.println("---------------------------------");
} else if (pcwahl == stein) {
System.out.println("Der Computer gewinnt mit 'Stein'");
System.out.println("---------------------------------");
} else {
System.out.println("Du gewinnst");
System.out.println("---------------------------------");
System.out.println("Der Computer wählte Papier ");
System.out.println("---------------------------------");
}
}
else if (spielerwahl == stein) {
if (spielerwahl == pcwahl) {
System.out.println("Keiner Gewinnt.");
System.out.println("---------------------------------");
} else if (pcwahl == papier) {
System.out.println("Der Computer gewinnt mit 'Papier'");
System.out.println("---------------------------------");
} else {
System.out.println("Du gewinnst!");
System.out.println("---------------------------------");
System.out.println("Der Computer wählte Schere ");
System.out.println("---------------------------------");
}
}
else if (spielerwahl == papier) {
if (spielerwahl == pcwahl) {
System.out.println("Keiner gewinnt.");
System.out.println("---------------------------------");
} else if (pcwahl == schere) {
System.out.println("Der Computer gewinnt mit 'Schere'");
System.out.println("---------------------------------");
} else {
System.out.println("Du gewinnst");
System.out.println("---------------------------------");
System.out.println("Der Computer wählte Papier");
System.out.println("---------------------------------");
}
}
} while (true);
}
}