Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BubbleSorting {
- public void sort(int[] array) {
- int temp = 0;
- for (int i = 0; i <= array.length - 1; i++) {
- for (int j = i + 1; j <= array.length - 1; j++) {
- if (array[i] > array[j]) {
- temp = array[i];
- array[i] = array[j];
- array[j] = temp;
- }
- }
- System.out.println(array[i]);
- }
- }
- public static void main(String[] args) {
- int[] array = {4, 2, 9, 5, 7, 8, 1};
- new BubbleSorting().sort(array);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement