weydile228

Untitled

Sep 29th, 2018
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.98 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Random;
  3.  
  4. public class lottery {
  5.  
  6.     private static void buyTicket(int ticket[]) {
  7.         Random rand = new Random();
  8.         for (int i = 0; i < ticket.length; i++) {
  9.             ticket[i] = (rand.nextInt(49) + 1);
  10.         }
  11.     }
  12.  
  13.     private static void wonCombination(int[] wonComb) {
  14.         Random rand = new Random();
  15.         for (int i = 0; i < wonComb.length; i++) {
  16.             wonComb[i] = (rand.nextInt(49) + 1);
  17.         }
  18.     }
  19.  
  20.     private static int checkTicket(int comb[]) {
  21.         int tmp = 0;
  22.         int ticket[] = new int[6];
  23.         buyTicket(ticket);
  24.         for (int i = 0; i < ticket.length; i++) {
  25.             for (int aTicket : ticket) {
  26.                 if (aTicket == comb[i]) {
  27.                     tmp++;
  28.                 }
  29.             }
  30.         }
  31.         return tmp;
  32.     }
  33.  
  34.     private static void results(int amount, int comb[], int price) {
  35.         int z = 0, q = 0, x = 0, g = 0, s = 0;
  36.         for (int i = 0; i < amount; i++) {
  37.             int tmp = checkTicket(comb);
  38.             if (tmp == 2) {
  39.                 z++;
  40.             } else if (tmp == 3) {
  41.                 q++;
  42.             } else if (tmp == 4) {
  43.                 x++;
  44.             } else if (tmp == 5) {
  45.                 g++;
  46.             } else if (tmp == 6) {
  47.                 s++;
  48.             }
  49.         }
  50.         z *= 100;
  51.         if (q > 0)
  52.             q = ((amount * price) / 18) / q;
  53.         if (x > 0)
  54.             x = ((amount * price) / 8) / x;
  55.         if (g > 0)
  56.             g = ((amount * price) / 16) / g;
  57.         if (s > 0)
  58.             s = ((amount * price) / 56) / s;
  59.         System.out.printf("При затратах в %d рублей выиграно %d", (price * amount), (z + q + x + g + s));
  60.     }
  61.  
  62.  
  63.     public static void main(String[] args) {
  64.         int comb[] = new int[6];
  65.         wonCombination(comb);
  66.         results(100000, comb, 160);
  67.         System.out.println(Arrays.toString(comb));
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment