SHARE
TWEET

pp

a guest Feb 21st, 2020 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package sample;
  2.  
  3. import javafx.event.ActionEvent;
  4. import javafx.scene.control.Label;
  5.  
  6. import java.util.Arrays;
  7. import java.util.Random;
  8.  
  9. public class Controller {
  10.     public Label keno;
  11.     public Label loto;
  12.     public Random rn = new Random();
  13.  
  14.     public void losuj(ActionEvent event) {
  15.  
  16.  
  17.         String pom = "";
  18.         int [] ken = zrebuj(10, 80);
  19.         pom = Arrays.toString(ken);
  20.         pom = pom.substring(1, pom.length() - 1);
  21.         keno.setText(pom);
  22.  
  23.  
  24.         ken = zrebuj(5, 35);
  25.         pom = Arrays.toString(ken);
  26.         pom = pom.substring(1, pom.length() - 1);
  27.         loto.setText(pom);
  28.     }
  29.  
  30.     private int[] zrebuj(int pocet, int max) {
  31.         int [] cisla = new int[pocet];
  32.         for (int i = 0; i < cisla.length; i++) {
  33.             int tah = rn.nextInt(max) + 1;
  34.             if (jeTam(cisla, tah)==false)
  35.                 cisla[i]=tah;
  36.             else
  37.                 i--;
  38.         }
  39.         Arrays.sort(cisla);
  40.         return cisla;
  41.     }
  42.     private boolean jeTam(int[] cisla, int tah){
  43.         for (int i = 0; i < cisla.length; i++) {
  44.             if (cisla[i] == tah)
  45.                 return true;
  46.             else
  47.                 return false;
  48.         }
  49.     }
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top