lunes, 2 de febrero de 2015

ejercicio 4 tema3

package ejercicio4;
import java.util.Random;

/**
 *
 * @author juan
 */
public class Ejercicio4 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        int [] numeros = new int[100];
        int [] ocurren = new int[10];
        Random r = new Random();
        int cont;
       
        for (int i = 0; i < numeros.length; i++) {
            numeros[i]= r.nextInt(31)+20;
        }
       
        cont=0;
        for (int i = 0; i < numeros.length; i++) {
            System.out.print(numeros[i]+",");
            ++cont;
            if (cont==20) {
                System.out.println("");
                cont=0;
            }
        }
        for (int num : numeros) {
            if (num>20 && num <31 p="">                ocurren[(num-21)]++;
        }
     
     
        for (int i = 0; i < ocurren.length; i++) {
            System.out.println("El número: "+ (21+i)+ " aparece "+ ocurren[i]+ " veces");
        }
    /*
        switch (num) {
            case 21: ocurren[0]++;break;
            case 22: ocurren[1]++;
                     break;
               
                break;
            default:
                throw new AssertionError();
        }
            */
    }
   
}

No hay comentarios: