Pr0gramer

VECTOR INT DE 5, AUTO-ORDENADO

Sep 9th, 2018
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. package vector_orden;
  2. import java.util.Scanner;
  3. public class Vector_orden {
  4. public Scanner key;
  5. private int[] sueldos;
  6. public void cargar() {
  7.     key = new Scanner(System.in);
  8.     sueldos = new int[5];
  9.     for (int f=0;f<5;f++) {
  10.         System.out.print("Ingrese un numero: ");
  11.         sueldos[f]=key.nextInt();
  12.     }
  13. }
  14. public void orden() {
  15.     int aux;
  16.     for (int k=0;k<sueldos.length-1;k++) {
  17.         for (int f=0;f<sueldos.length-1;f++) {
  18.             if (sueldos[f]>sueldos[f+1]) {
  19.                 aux=sueldos[f];
  20.                 sueldos[f]=sueldos[f+1];
  21.                 sueldos[f+1]=aux;
  22.             }
  23.         }
  24.     }
  25.     for (int m=0;m<5;m++) {
  26.         System.out.println(sueldos[m]);
  27.     }
  28. }
  29.     public static void main(String[] args) {
  30.     Vector_orden load=new Vector_orden();
  31.     load.cargar();
  32.     load.orden();
  33.     }    
  34. }
Advertisement
Add Comment
Please, Sign In to add comment