1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| package com.lete.Java.Test;
import java.util.Arrays;
public class BubbleSort { public static void main(String[] args) { int arr[] = {10,2,15,33,1,6,8}; int temp;
for (int i = 1; i < arr.length; i++) { for (int j = 0; j < arr.length; j++) { if(arr[i]<arr[j]){ temp = arr[i]; arr[i]=arr[j]; arr[j]=temp; } } } System.out.println(Arrays.toString(arr)); } }
|