Advertisement
Guest User

Untitled

a guest
May 19th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class rzutMoneta {
  4.    private int wynik;
  5.  
  6. private int iloscRzutow=0;
  7.  
  8.   public void rzut(){
  9. String [] mozliwosci= new String[2];
  10. mozliwosci[0]="orzel";
  11. mozliwosci[1]="reszka";
  12.  
  13.  
  14.        while (iloscRzutow<5){
  15.             Scanner scan = new Scanner(System.in);
  16.            System.out.println("Proba numer "+(iloscRzutow+1));
  17.             System.out.println("Orzel czy reszka?");
  18.             String typ = scan.nextLine();
  19.             wynik=(int)(Math.random()*2);
  20.             System.out.println("Twoj wybor to:"+typ);
  21.             System.out.println("Wypadl/a "+ mozliwosci[wynik]);
  22.  
  23.             if(mozliwosci[wynik].equalsIgnoreCase(typ)){
  24.  
  25.                 System.out.println("Trafiles!!\n");
  26.  
  27.             }
  28.  
  29.             else {
  30.                 System.out.println("Niestety, nie trafiles\n");
  31.             }
  32.  
  33. iloscRzutow++;
  34.  
  35.         }
  36.     }
  37.     }
  38.  
  39.  
  40. class rzutMonetaTest{
  41. public static void main(String[] args){
  42.     System.out.println("Masz piec rzutow moneta.");
  43.     rzutMoneta gra=new rzutMoneta();
  44. gra.rzut();
  45.     System.out.println("Gra zakonczona.");
  46.  
  47.  
  48.  
  49. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement