Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Random;
- public class lottery {
- private static void buyTicket(int ticket[]) {
- Random rand = new Random();
- for (int i = 0; i < ticket.length; i++) {
- ticket[i] = (rand.nextInt(49) + 1);
- }
- }
- private static void wonCombination(int[] wonComb) {
- Random rand = new Random();
- for (int i = 0; i < wonComb.length; i++) {
- wonComb[i] = (rand.nextInt(49) + 1);
- }
- }
- private static int checkTicket(int comb[]) {
- int tmp = 0;
- int ticket[] = new int[6];
- buyTicket(ticket);
- for (int i = 0; i < ticket.length; i++) {
- for (int aTicket : ticket) {
- if (aTicket == comb[i]) {
- tmp++;
- }
- }
- }
- return tmp;
- }
- private static void results(int amount, int comb[], int price) {
- int z = 0, q = 0, x = 0, g = 0, s = 0;
- for (int i = 0; i < amount; i++) {
- int tmp = checkTicket(comb);
- if (tmp == 2) {
- z++;
- } else if (tmp == 3) {
- q++;
- } else if (tmp == 4) {
- x++;
- } else if (tmp == 5) {
- g++;
- } else if (tmp == 6) {
- s++;
- }
- }
- z *= 100;
- if (q > 0)
- q = ((amount * price) / 18) / q;
- if (x > 0)
- x = ((amount * price) / 8) / x;
- if (g > 0)
- g = ((amount * price) / 16) / g;
- if (s > 0)
- s = ((amount * price) / 56) / s;
- System.out.printf("При затратах в %d рублей выиграно %d", (price * amount), (z + q + x + g + s));
- }
- public static void main(String[] args) {
- int comb[] = new int[6];
- wonCombination(comb);
- results(100000, comb, 160);
- System.out.println(Arrays.toString(comb));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment