lucasmouraahere

Ordem crescente

Dec 15th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class OrdemCrescente {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner sc = new Scanner(System.in);
  7.        
  8.         int num;
  9.        
  10.         System.out.println("Entre com a quantidade de números para ser ordenado em ordem crescente: ");
  11.         num = sc.nextInt();
  12.        
  13.         int [] valores = new int [num];
  14.        
  15.         for(int i = 0; i < num; i++){
  16.             System.out.println("Entre com os números para ser ordenado em ordem crescente: ");
  17.             valores[i] = sc.nextInt();
  18.         }
  19.        
  20.         int aux;
  21.        
  22.         for(int i = 0; i < num-1; i++){
  23.             if(valores[i] < valores[i+1]){
  24.             aux = valores[i];
  25.             valores[i] = valores[i+1];
  26.             valores[i+1] = aux;
  27.             i = -1;
  28.             }
  29.         }
  30.  
  31.         for(int i = 0; i < num; i++){
  32.             System.out.println(valores[i]);
  33.         }
  34.     }
  35.  
  36. }
Add Comment
Please, Sign In to add comment