chillurbrain

Task8_6_3

Dec 18th, 2015
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class Task8_6_3 {
  4.     public static void main(String[] args) {
  5.         Scanner sc = new Scanner(System.in);
  6.         int n = sc.nextInt();
  7.         int[] numArr = new int[n];
  8.         for (int i = 0; i < n; i++) {
  9.             numArr[i] = sc.nextInt();
  10.         }
  11.         bubbleSort(numArr, n);
  12.     }
  13.     public static void bubbleSort(int[] a, int n) {
  14.         for (int i = n - 1; i > 1; i--)
  15.             for (int j = 0; j < i; j++)
  16.                 if (a[j] > a[j+1]) {
  17.                     int temp = a[j];
  18.                     a[j] = a[j+1];
  19.                     a[j+1] = temp;
  20.                 }
  21.         for (int i = 0; i < n; i++) {
  22.             System.out.print(a[i] + " ");
  23.         }
  24.     }
  25. }
Add Comment
Please, Sign In to add comment