Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class Task8_6_3 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- int[] numArr = new int[n];
- for (int i = 0; i < n; i++) {
- numArr[i] = sc.nextInt();
- }
- bubbleSort(numArr, n);
- }
- public static void bubbleSort(int[] a, int n) {
- for (int i = n - 1; i > 1; i--)
- for (int j = 0; j < i; j++)
- if (a[j] > a[j+1]) {
- int temp = a[j];
- a[j] = a[j+1];
- a[j+1] = temp;
- }
- for (int i = 0; i < n; i++) {
- System.out.print(a[i] + " ");
- }
- }
- }
Add Comment
Please, Sign In to add comment