Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Package gluecksspiel;
- import java.io.*;
- import java.util.Random;
- public class Gluecksspiel {
- public static void main(String[] args) throws IOException {
- int zufallszahl,zahl1,zahl2;
- String tmp;
- BufferedReader einlesen = new BufferedReader(new InputStreamReader(System.in));
- System.out.println("Spieler 1 bitte Zahl eingeben: ");
- tmp = einlesen.readLine();
- zahl1 = Integer.parseInt(tmp);
- System.out.println("Spieler 2 bitte Zahl eingeben: ");
- tmp = einlesen.readLine();
- zahl2 = Integer.parseInt(tmp);
- Random ZufaGenerator = new Random();
- zufallszahl = ZufaGenerator.nextInt(51);
- zahl1 = zufallszahl - zahl1;
- zahl2 = zufallszahl - zahl2;
- if(zahl1 < 0) {
- zahl1 = Math.abs(zahl1);
- }
- if(zahl2 < 0) {
- zahl2 = Math.abs(zahl2);
- }
- if (zahl1 > 50) {
- System.out.println("Error");
- }
- else if (zahl1 < 1) {
- System.out.println("Error");
- }
- else if (zahl2 > 50) {
- System.out.println("Error");
- }
- else if (zahl2 < 1) {
- System.out.println("Error");
- }
- else if (zahl1 > zahl2) {
- System.out.println("Die Zufallszahl lautet: "+zufallszahl);
- System.out.println("Spieler 2 hat gewonnen");
- }
- else if (zahl1 < zahl2) {
- System.out.println("Die Zufallszahl lautet: "+zufallszahl);
- System.out.println("Spieler 1 hat gewonnen");
- }
- else {
- System.out.println("Die Zufallszahl lautet: "+zufallszahl);
- System.out.println("Unentschieden");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement