Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. package com.company;
  2. import java.util.Scanner;
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         Scanner read = new Scanner(System.in);
  8.         int size = read.nextInt();
  9.  
  10.         int array[] = new int[size+1];
  11.  
  12.         int i = 0;
  13.         while(i < size){
  14.             int tmp = read.nextInt();
  15.             if( i == 0){
  16.                 array[i] = tmp;
  17.             }
  18.             else{
  19.                 for(int j = 0; j < i; j++){
  20.                     if(tmp < array[j]){
  21.                         for(int t = i; t > j; t--){
  22.                             array[t] = array[t-1];
  23.                         }
  24.                         array[j] = tmp;
  25.                         break;
  26.                     }
  27.                     if(j == i-1){
  28.                         array[i] = tmp;
  29.                     }
  30.                 }
  31.             }
  32.             i++;
  33.         }
  34.  
  35.         for(int j = 0; j < size; j++){
  36.             System.out.println(array[j]);
  37.         }
  38.  
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement