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]+" ");
}
}
}
Nesta página do site você pode assistir ao vídeo on-line Java Basics - Session - 10 - How to SORT an Array using Loops (Bubble Sort) duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Khan's Tech Lab 13 Julho 2025, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 52 vezes e gostou 2 espectadores. Boa visualização!