Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Implementujte telo metody *nadprumer*, ktera vrati pocet prvku pole *pole*,
- * ktere jsou vetsi, nez aritmeticky prumer vsech prvku v poli.
- * int nadprumer(int[] pole) {
- */
- import java.util.Random;
- public class PrumerCiselVPoli {
- private static int[] poleCisel = new int[10];
- public static void main(String[] args) {
- Random rnd = new Random();
- for (int i = 0; i < 10; i++) {
- poleCisel[i] = rnd.nextInt();
- System.out.println("Cislo c. " + i + " " + poleCisel[i]);
- }
- System.out.println( nadprumer(poleCisel) + " je vetsich, nez prumer." );
- }
- private static int nadprumer(int[] pole) {
- int soucet = 0;
- float prumer = 0;
- for (int i = 0; i < pole.length; i++) {
- soucet += pole[i];
- }
- prumer = soucet / pole.length;
- System.out.println("Soucet = " + soucet);
- System.out.println("Prumer = " + prumer);
- int pocetVetsichNezPrumer = 0;
- for (int i = 0; i < pole.length; i++) {
- if (pole[i] > prumer) {
- pocetVetsichNezPrumer++;
- }
- }
- return pocetVetsichNezPrumer;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment