Java Basics - Session - 10 - How to SORT an Array using Loops (Bubble Sort)

Publié le: 13 juillet 2025
sur la chaîne: Khan's Tech Lab
52
2

In this video, we will learn How to SORT an Array using Loops.

0:00 Introduction

0:26 Steps

0:45 Understanding all steps with Excel

28:28 Understanding all steps with Code

Here is the program:
public class Sort {
public static void main(String[] args) {
//step - 1 - initializing array
int[] arr = {5, 9, 8, 7, 6, 1, 2, 10, 100, 0};
// step 2 - Defining Loops
// outer loop
for (int i = 0; i LT arr.length; i++) {
// inner loop
for (int j = i+1; j LT arr.length; j++) {
// step - 3 - Comparing Elements
if(arr[i] GT arr[j]){
// step 4 - Swapping if required
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
} // step - 5 - Print element
System.out.print(arr[i]+" ");
}
}
}


Sur cette page du site, vous pouvez voir la vidéo en ligne Java Basics - Session - 10 - How to SORT an Array using Loops (Bubble Sort) durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Khan's Tech Lab 13 juillet 2025, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 52 fois et il a aimé 2 téléspectateurs. Bon visionnage!