Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Pole
  4. {
  5. private int pocetAktPrvkov;
  6. private int[] udaje;
  7.  
  8.  
  9. public Pole ( int pocetPrvkovMax )
  10. {
  11. pocetAktPrvkov=0;
  12. udaje=new int[pocetPrvkovMax];
  13.  
  14. }
  15.  
  16. public Pole ()
  17. {
  18. this( 100 );
  19.  
  20.  
  21. }
  22.  
  23. public boolean naplnNahodne ( int pocet, int rozsahOd, int rozsahDo )
  24. {
  25. if ( pocet<1 || pocet>udaje.length )
  26. {
  27. return false;
  28.  
  29. }
  30.  
  31. Random rnd = new Random ();
  32.  
  33. for ( int i=0; i<pocet; i++ )
  34. {
  35. udaje[ i ] = rozsahOd + rnd.nextInt ( rozsahDo - rozsahOd +1 );
  36.  
  37. }
  38. pocetAktPrvkov = pocet;
  39.  
  40. return true;
  41. }
  42.  
  43. public int dajSucet ()
  44. {
  45.  
  46. int vysl=0;
  47.  
  48. for ( int i=0; i<pocetAktPrvkov; i++ )
  49. {
  50.  
  51. vysl=vysl+udaje[i];
  52.  
  53. }
  54.  
  55. return vysl;
  56.  
  57.  
  58. }
  59.  
  60. public double dajPriemer ()
  61. {
  62. return 1.0 * dajSucet () / pocetAktPrvkov;
  63.  
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement