Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. Package gluecksspiel;
  2.  
  3. import java.io.*;
  4. import java.util.Random;
  5.  
  6. public class Gluecksspiel {
  7.  
  8.  
  9. public static void main(String[] args) throws IOException {
  10. int zufallszahl,zahl1,zahl2;
  11. String tmp;
  12. BufferedReader einlesen = new BufferedReader(new InputStreamReader(System.in));
  13.  
  14.  
  15. System.out.println("Spieler 1 bitte Zahl eingeben: ");
  16. tmp = einlesen.readLine();
  17. zahl1 = Integer.parseInt(tmp);
  18.  
  19. System.out.println("Spieler 2 bitte Zahl eingeben: ");
  20. tmp = einlesen.readLine();
  21. zahl2 = Integer.parseInt(tmp);
  22.  
  23.  
  24.  
  25. Random ZufaGenerator = new Random();
  26. zufallszahl = ZufaGenerator.nextInt(51);
  27.  
  28. zahl1 = zufallszahl - zahl1;
  29. zahl2 = zufallszahl - zahl2;
  30.  
  31. if(zahl1 < 0) {
  32. zahl1 = Math.abs(zahl1);
  33. }
  34. if(zahl2 < 0) {
  35. zahl2 = Math.abs(zahl2);
  36. }
  37.  
  38. if (zahl1 > 50) {
  39. System.out.println("Error");
  40. }
  41. else if (zahl1 < 1) {
  42. System.out.println("Error");
  43. }
  44. else if (zahl2 > 50) {
  45. System.out.println("Error");
  46. }
  47. else if (zahl2 < 1) {
  48. System.out.println("Error");
  49. }
  50. else if (zahl1 > zahl2) {
  51. System.out.println("Die Zufallszahl lautet: "+zufallszahl);
  52. System.out.println("Spieler 2 hat gewonnen");
  53. }
  54. else if (zahl1 < zahl2) {
  55. System.out.println("Die Zufallszahl lautet: "+zufallszahl);
  56. System.out.println("Spieler 1 hat gewonnen");
  57. }
  58. else {
  59. System.out.println("Die Zufallszahl lautet: "+zufallszahl);
  60. System.out.println("Unentschieden");
  61. }
  62. }
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement