Ejercicio02.java 1.43 KB
Newer Older
Silvia Barrientos committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
public class Ejercicio02 {
    static final int X = 30;
    static final int Y = -30;
    static final int DIMENSION = 100;
    public static void main(String[] args) {
        
        int arrayNumeros[];
        arrayNumeros = new int[61];
        int indice = 0;
        int array[];
        array = new int[DIMENSION];
        int contador = Y;
        int mayor = 0;
        int numero = 0;
        for(int i = Y; i <= X; i++){
            arrayNumeros[indice] = 0;
            indice++;
        }
        
        for(int i = 0; i < array.length; i++){
            array[i] = (int)(Math.random()*(X-Y+1)+Y);
            System.out.printf(" " + array[i]);
        }
        indice = 0;
        while(contador <= X){
            for(int i = 0; i < array.length; i++){
                if(contador == array[i]){
                    arrayNumeros[indice]++;
                }
                
            }
            indice++;
            contador++;
        }
        
        indice = 0;
        System.out.printf("\nLos numeros que no estan presentes son: \n");
        for(int i = Y; i <= X; i++){
            if(arrayNumeros[indice] > mayor){
                mayor = arrayNumeros[indice];
                numero = i;
            }
            if(arrayNumeros[indice] == 0){
                System.out.printf("\t %d", i);
            }
            indice++;
        }
        System.out.printf("\nEl numero que más se repite es: %d\n", + numero);
    }
}