Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
967 B
3
Indexable
import java.util.Random;

public class Main {
    public static void main(String[] args) {
        Double[] array = new Double[]{0.4, -0.5, 3.15, 2.0, 0.24, 10.0, 2.17, 966.0, 23.0};
        System.out.println("\ndla danych testowych");
        zad2(array);
        Double[] arrayRandomValue = new Double[50];
        Random r = new Random();
        for ( int i=0;i<50;i++ ){
            arrayRandomValue[i] = 2.0 + (40 - 2) * r.nextDouble();
        }
        System.out.println("\ndla wylosowanych liczb");
        zad2(arrayRandomValue);
    }

    static void zad2(Double[] tab) {
        for (int i = 0; i < tab.length; i++) {
            if ( czyKwadrat(i) ){
                System.out.print(tab[i] + " ");
            }
        }
    }

    static boolean czyKwadrat(int x) {

        for (int i = 0; i <= x; i++) {
            if ( i*i==x ){
                return true;
            }
        }
        return false;
    }
}