Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Ejercicios;
- import javax.swing.*;
- public class Ejercicio8 {
- /* Ejercicio 8
- Capturar 10 números del usuario y almacenarlos en una lista.
- Luego, la lista debe ser ordenada, y obtener el elemento menor y mayor.
- */
- public static void main(String[] args) {
- String Posicion[] = { "Posición1","Posición2","Posición3","Posición4","Posición5","Posición6","Posición7","Posición8","Posición9","Posición10" };
- int arreglo [] = new int [10];
- int numero ;
- for (int j = 0 ; j < arreglo.length; ++j){
- numero = Integer.parseInt(JOptionPane.showInputDialog( " digite 10 numeros diferentes: " + Posicion[j ]));
- arreglo[j] = numero;
- }
- for (int j = 0 ; j < arreglo.length; ++j){
- System.out.println("Numero " + Posicion [j] + " : " + arreglo[j]);
- }
- int posnumeroMayor = 0;
- int numeroMayor = arreglo[posnumeroMayor];
- for (int j = 1 ; j < arreglo.length ; ++j){
- if(arreglo[j] > numeroMayor){
- numeroMayor = arreglo[j];
- posnumeroMayor = j;
- }
- }
- System.out.println("num[numeroMayor] = " + arreglo[posnumeroMayor]);
- int posNumeroMenor = 0;
- int numeroMenor = arreglo[posNumeroMenor];
- for (int j = 1; j < arreglo.length; ++j){
- if (arreglo[j]< numeroMenor){
- numeroMenor = arreglo[j];
- posNumeroMenor = j;
- }
- }
- System.out.println("num[posNumeroMenor] = " + arreglo[posNumeroMenor]);
- int aux;
- for (int j = 0 ; j<arreglo.length; ++j ){
- for(int k = j + 1 ; k < arreglo.length; ++k){
- if (arreglo[j]< arreglo[k] ){
- aux = arreglo[j];
- arreglo [j] = arreglo[k];
- arreglo[k] = aux ;
- }
- }
- }
- System.out.println("arreglo = { ");
- for (int j = 0 ; j < arreglo.length; ++j){
- System.out.println(arreglo [j]+ " , ");
- }
- System.out.println("}");
- for (int j = 0 ; j<arreglo.length; ++j ){
- for(int k = j + 1 ; k < arreglo.length; ++k){
- if (arreglo[j]> arreglo[k] ){
- aux = arreglo[j];
- arreglo [j] = arreglo[k];
- arreglo[k] = aux ;
- }
- }
- }
- System.out.println("arreglo = { ");
- for (int j = 0 ; j < arreglo.length; ++j){
- System.out.println(arreglo [j]+ " , ");
- }
- System.out.println("}");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement