Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9103f51

Browse files
authored
Merge pull request#159 from Poulami769988/main
Bubble Sort using Java.
2 parentsf7c1d70 +cc23506 commit9103f51

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

‎BubbleSort1.java‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
importjava.util.*;
2+
classBubbleSort1{
3+
// Bubble Sort Function
4+
publicstaticvoidBubbleSort(intarr[]){
5+
for(inti=0;i<=arr.length-1;i++){
6+
// Inner loop to visit two adjacent elements
7+
for(intj=0;j<arr.length-1-i;j++){
8+
// Swaping two adjacent elements
9+
if (arr[j]>arr[j+1]){
10+
inttemp=arr[j];
11+
arr[j]=arr[j+1];
12+
arr[j+1]=temp;
13+
}
14+
}
15+
}
16+
}
17+
// Function to print Array
18+
publicstaticvoidPrintArray(intarr[]){
19+
for (inti=0;i<arr.length;i++)
20+
System.out.print(arr[i]+" ");
21+
}
22+
23+
publicstaticvoidmain(String[]args){
24+
Scannersc=newScanner(System.in);
25+
intarr[]=newint[5];
26+
for(inti=0;i<arr.length;i++)
27+
arr[i]=sc.nextInt();
28+
sc.close();
29+
30+
BubbleSort(arr);
31+
PrintArray(arr);
32+
}
33+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp