GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Java/Programs/BubbleSort.java at main · Koder-Sunil/Java Expand file tree/ Copy pathBubbleSort.javaMore file actions 23 lines (23 loc) · 767 Bytes / Copy pathBubbleSort.javaFile metadata and controls23 lines (23 loc) · 767 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 // Program to sort an array in Java (using bubble sort) - public class BubbleSort { public static void main(String[] args) { int arr[] = {10, 45, 15, 13, 54}; // Initializing an array int temp; // Two for loops to traverse the array - for (int i = 0; i < arr.length - 1; i++) { for (int j = i + 1; j < arr.length; j++) { // check if element is greater - if (arr[i] > arr[j]) { temp = arr[i]; // assign arr[i] element to temp position arr[i] = arr[j]; // assign arr[j] element to arr[i] position arr[j] = temp; // assign temp value to arr[j] position } } } System.out.println("Sorted array: "); // For loop to print the sorted array - for (int i = 0; i < arr.length; i++) { System.out.println(arr[i]); } } } |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |