Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package izapr_cv04;
- import java.util.Arrays;
- public class Izapr_cv04 {
- public static void main(String[] args) {
- int[] pole = new int[50];
- int min = 1, max = 90;
- naplnPole(pole, min, max);
- vypisPole(pole);
- System.out.println("Součet prvků pole je:" + soucetPrvku(pole));
- nejvetsiCislo(pole, min, max);
- System.out.println("" + Arrays.toString(pole)); // Jiná možnost zápisu výpisu.
- }
- public static void nejvetsiCislo(int pole[], int max, int min)
- {
- int indexMin = -1, indexMax = -1;
- for (int i = 0; i < pole.length; i++) {
- if (max <= pole[i]) {
- max = pole[i];
- indexMax = i;
- }
- if (min >= pole[i]) {
- min = pole[i];
- indexMin = i;
- }
- }
- System.out.println("Největší číslo v poli je:" + max + " na pozici: " + indexMax);
- System.out.println("Nejmenší číslo v poli je:" + min + " na pozici: " + indexMin);
- }
- public static void naplnPole(int pole[], int min, int max){
- for (int i = 0; i < pole.length; i++) {
- pole[i] = generujCislo(min,max);
- }
- }
- public static int soucetPrvku(int pole[])
- {
- int soucet = 0;
- for (int i = 0; i < pole.length; i++) {
- soucet += pole[i];
- }
- return soucet;
- }
- public static void vypisPole(int pole[]){
- for (int i = 0; i < pole.length; i++) {
- //for(prvek:pole)
- System.out.print(pole[i] /*nebo prvek*/+",");
- }
- System.out.println();
- }
- public static int generujCislo(int min, int max){
- return (int) Math.round(Math.random() * (max - min) + min);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment