1. Dado
el siguiente código donde captura 2
listas de números luego suma cada lista y las compara y dice cual es la mayor:
SE DEBE ORGANIZAR EL EJERCICIO DE MANERA TAL QUE CAPTURE 2 LISTAS DE ARREGLO
(Arreglos unidimensionales) , los cuales
los suma y luego
Hace la comparación de los dos arreglos
diciendo cual es el mayor de los arreglos.
CÓDIGO FUENTE
package manu;
import javax.swing.JOptionPane;
/**
*
* @author Admin
*/
public class Discretas {
public static void main(String[] args) {
int suma=0, suma1=0;
String[]
vec=JOptionPane.showInputDialog("INGRESE LOS COMPONENTES DE LA LISTA 1 DE
LA FORMA\n 1,2,3,4,5,6,7,8,9,,,N").split(",");
String[]
vec1=JOptionPane.showInputDialog("INGRESE LOS COMPONENTES DE LA LISTA 2 DE
LA FORMA\n 1,2,3,4,5,6,7,8,9,,,N").split(",");
int[] vec2 = new int[vec.length];
int[] vec2x = new
int[vec1.length];
for (int i=0; i<vec.length; i++)
{
vec2[i] =
Integer.parseInt(vec[i]);
suma=vec2[i]+suma;
}
for (int i=0; i<vec1.length;
i++) {
vec2x[i] =
Integer.parseInt(vec1[i]);
suma1=vec2x[i]+suma1;
}
System.out.println("lista 1:
"+suma+"\n"+ "lista 2: "+suma1);
if (suma>suma1) {
System.out.print("LA LISTA
1 ES MAYOR");
} else if (suma<suma1){
System.out.print("LA LISTA 2
ES MAYOR");
}else{
System.out.print("LAS LISTAS
SON IGUALES");
}
}
}
SALIDA


No hay comentarios.:
Publicar un comentario