Arrangements, random numbers and compare

0

Occupy helps, I have to make a program that fills two arrays with random numbers, then compare sume two numbers of an arrangement and compare them with the sum of the second, and indicate which is the largest number.

The problem is that I do not understand well how to do the first part, I tried to generate a random number code but I do not know how to save it in the array.

Code for random:

for (int i = 0; i < 14; i++) {
        Random generadorAleatorios = new Random();

        int numeroAleatorio = 1 + generadorAleatorios.nextInt(14);


            System.out.println(numeroAleatorio);
        }

Then to compare them I have this code:

Double compNumeros[];// arreglo para comparar numeros
    compNumeros = new Double[10];
        System.out.println("");// para dejar un espacio en pantalla
        try {
            System.out.println("Debe de ingresar 10 digitos decimales");
            for (int i = 0; i < compNumeros.length; i++) {
            System.out.println("Digite el valor a ingresar:");
             compNumeros[i] = teclado.nextDouble();
             teclado.nextLine();

            }
        } catch (Exception e) {
            System.out.println("Ingreso un dato erroneo");
            System.out.println("Vuelva a Iniciar el programa");
        }
        Double max, min;
        min = max = compNumeros[0];
        for (int i = 0; i < compNumeros.length; i++) {
            if (min > compNumeros[i]) {
                min = compNumeros[i];                
                }
            if (max < compNumeros[i]) {
                max = compNumeros[i];

            }
            System.out.println("Segun el analisis realizado, los datos son los siguientes:");
            System.out.println("El Numero Mayor ingresado es: " + max);
            System.out.println("El Numero Minimo Ingresado es: " + min);
            System.out.println("Fin del Programa");

But I have problems with the part of how to save in the arrangements.

I thank you for guiding me

    
asked by Felix mejias 12.07.2018 в 17:59
source

1 answer

0

Friend to be able to make the vector is random numbers you can use your same function, but I know that you use this other method of the Math class:

    double[] arreglo1 = new double[10];
    double[] arreglo2 = new double[10];
    int valorEntero = 0;
        for (int i = 0; i < arreglo1.length; i++) {
               //para conseguir un número entero entre M y N con M menor
               //que N y ambos incluídos, debes usar esta fórmula
               valorEntero = Math.floor(Math.random()*(N-M+1)+M);
               //Luego debes incluir ese numero aleatorio en el vector
               arreglo1[i] = valorEntero;

               valorEntero = Math.floor(Math.random()*(N-M+1)+M);
               //Luego debes incluir ese numero aleatorio en el vector
               arreglo2[i] = valorEntero;
        }

        //loops para hacer la suma de cada arreglo
        int suma1 = 0;
        int suma2 = 0;

        for(int i = 0; i < arreglo1.length; i++){

            suma1 += arreglo1[i];
            suma2 += arreglo2[i];


        }

    //condicional para ver cual es mayor

        if(suma1 < suma2){

            System.out.println("El arreglo1 es mayor con la suma de:" + suma1 );

        }else if(suma 1 > suma2){

            System.out.println("El arreglo2 es mayor con la suma de:" + suma2);
        }else {

            System.out.println("los dos arreglos dan la misma suma");
        }

I did not understand you very well, tell me and I will continue to help you

    
answered by 12.07.2018 в 18:24