Advertisement
myname0

Java_Task_1

Oct 5th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. package com.ssu.liza_eliseeva.task1;
  2. import java.util.Scanner;
  3. public class Main {
  4.  
  5.     public static void Sort (int [] array)
  6.     {
  7.         int temp;
  8.         int j;
  9.         for(int i = 1; i < array.length; ++i) {
  10.             temp = array[i];
  11.             for( j = i-1; (j >= 0) && (temp < array[j]); j--)
  12.                 array[j+1] = array[j];
  13.             array[j+1] = temp;
  14.         }
  15.  
  16.     }
  17.     public static void main(String[] args) {
  18.         System.out.println("Enter count elements of array: ");
  19.         Scanner in = new Scanner(System.in);
  20.         int count = in.nextInt();
  21.  
  22.         int [] array = new int[count];
  23.         System.out.println("Enter array: ");
  24.         for( int i = 0; i < count; i++){
  25.             array[i] = in.nextInt();
  26.         }
  27.  
  28.         Sort(array);
  29.  
  30.         for(int i = 0; i < count; i++){
  31.             System.out.print(array[i] + " ");
  32.         }
  33.  
  34.  
  35.  
  36.     // write your code here
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement