GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Java/Programs/BubbleSort.java at main · Koder-Sunil/Java

Expand file tree

/

BubbleSort.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
23 lines (23 loc) · 767 Bytes
/

BubbleSort.java

Copy path

File metadata and controls

23 lines (23 loc) · 767 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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.