Advertisement
Guill

Aula vec

Sep 9th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. package javaapplication3;
  2. import java.util.Scanner;
  3. public class JavaApplication3 {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner input = new Scanner(System.in);
  7.         int i = 0;
  8.         int[] vec = new int[10];
  9.         while(i < 10){
  10.             System.out.println("n ");
  11.             vec[i] = input.nextInt();
  12.             i +=1;
  13.         }
  14.         int[] sample = vec;
  15.         i = 0;
  16.         int j = i + 1;
  17.         int aux;
  18.         while(i < sample.length){
  19.             while(j < sample.length){
  20.                 if(sample[i] < sample[j]){
  21.                     aux = sample[j];
  22.                     while(j > i){
  23.                         j = j - 1;
  24.                         sample[j + 1] = sample[j];                              
  25.                     }
  26.                     sample[j] = aux;
  27.                     j = i + 1;  
  28.                 }
  29.                 else{
  30.                     j += 1;
  31.                 }
  32.             }
  33.             i += 1;
  34.             j = 1 + i;
  35.         }
  36.         i = 0;
  37.         while(i < sample.length){
  38.             System.out.println(sample[i]);
  39.             i += 1;
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement