Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Pole
- {
- private int pocetAktPrvkov;
- private int[] udaje;
- public Pole ( int pocetPrvkovMax )
- {
- pocetAktPrvkov=0;
- udaje=new int[pocetPrvkovMax];
- }
- public Pole ()
- {
- this( 100 );
- }
- public boolean naplnNahodne ( int pocet, int rozsahOd, int rozsahDo )
- {
- if ( pocet<1 || pocet>udaje.length )
- {
- return false;
- }
- Random rnd = new Random ();
- for ( int i=0; i<pocet; i++ )
- {
- udaje[ i ] = rozsahOd + rnd.nextInt ( rozsahDo - rozsahOd +1 );
- }
- pocetAktPrvkov = pocet;
- return true;
- }
- public int dajSucet ()
- {
- int vysl=0;
- for ( int i=0; i<pocetAktPrvkov; i++ )
- {
- vysl=vysl+udaje[i];
- }
- return vysl;
- }
- public double dajPriemer ()
- {
- return 1.0 * dajSucet () / pocetAktPrvkov;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement