Advertisement
SoniaMilena

Ejercico 8

Apr 17th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.65 KB | None | 0 0
  1. package Ejercicios;
  2. import javax.swing.*;
  3. public class Ejercicio8 {
  4.     /*  Ejercicio 8
  5.         Capturar 10 números del usuario y almacenarlos en una lista.
  6.         Luego, la lista debe ser ordenada, y obtener el elemento menor y mayor.
  7.     */
  8.     public static void main(String[] args) {
  9.         String Posicion[] = { "Posición1","Posición2","Posición3","Posición4","Posición5","Posición6","Posición7","Posición8","Posición9","Posición10" };
  10.         int arreglo [] = new int [10];
  11.         int numero ;
  12.  
  13.         for (int j = 0 ; j < arreglo.length; ++j){
  14.             numero = Integer.parseInt(JOptionPane.showInputDialog( " digite 10 numeros diferentes: " + Posicion[j ]));
  15.             arreglo[j] = numero;
  16.         }
  17.         for (int j =  0 ; j < arreglo.length; ++j){
  18.             System.out.println("Numero  " + Posicion [j] + " : "   + arreglo[j]);
  19.         }
  20.         int posnumeroMayor = 0;
  21.         int numeroMayor = arreglo[posnumeroMayor];
  22.         for (int j = 1 ; j < arreglo.length ; ++j){
  23.             if(arreglo[j] > numeroMayor){
  24.                 numeroMayor = arreglo[j];
  25.                 posnumeroMayor = j;
  26.             }
  27.         }
  28.         System.out.println("num[numeroMayor] = " + arreglo[posnumeroMayor]);
  29.        
  30.         int posNumeroMenor = 0;
  31.         int numeroMenor = arreglo[posNumeroMenor];
  32.         for (int j = 1; j < arreglo.length; ++j){
  33.             if (arreglo[j]< numeroMenor){
  34.                 numeroMenor = arreglo[j];
  35.                 posNumeroMenor = j;
  36.             }
  37.         }
  38.         System.out.println("num[posNumeroMenor] = " + arreglo[posNumeroMenor]);
  39.         int aux;
  40.  
  41.         for (int j = 0 ; j<arreglo.length; ++j ){
  42.             for(int k = j + 1  ; k < arreglo.length; ++k){
  43.                 if   (arreglo[j]< arreglo[k] ){
  44.                     aux = arreglo[j];
  45.                     arreglo [j] = arreglo[k];
  46.                     arreglo[k] = aux ;
  47.                 }
  48.             }
  49.         }
  50.         System.out.println("arreglo  = { ");
  51.         for (int j = 0 ; j < arreglo.length; ++j){
  52.             System.out.println(arreglo [j]+ " , ");
  53.         }
  54.         System.out.println("}");
  55.         for (int j = 0 ; j<arreglo.length; ++j ){
  56.             for(int k = j + 1  ; k < arreglo.length; ++k){
  57.                 if   (arreglo[j]> arreglo[k] ){
  58.                     aux = arreglo[j];
  59.                     arreglo [j] = arreglo[k];
  60.                     arreglo[k] = aux ;
  61.                 }
  62.             }
  63.         }
  64.         System.out.println("arreglo  = { ");
  65.         for (int j = 0 ; j < arreglo.length; ++j){
  66.             System.out.println(arreglo [j]+ " , ");
  67.         }
  68.         System.out.println("}");
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement