Wednesday, December 19
BubbleSort program in Java
Hi All,
package Sorting;
/**
*
* @author SKiTECH
*/
public class bubbleSort {
public static void main(String arg[]) {
int a[] = {100, 30, 80, 20, 2, 90, 50, 11, 99, 99};
int temp = 0;
System.out.println("Ascending sort program");
for (int i = a.length - 1; i >= 0; i--) {
for (int j = 0; j < i; j++) {
if (a[j] < a[j + 1])
{ // if you want descending order change ">" symbol instead of "<" (a[j] > a[j + 1])
temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
System.out.println(a[i]);
}
}
}
OUTPUT:
~~~~~~~~
Ascending sort program
2
11
20
30
50
80
90
99
99
100
Descending sort program
100
99
99
90
80
50
30
20
11
2
Subscribe to:
Post Comments (Atom)
Backup files to google drive using PHP coding
Dear All, To backup files to Google Drive using PHP coding, you can use the Google Drive API and the Google Client Library for PHP. Here...
-
Hi Guys, Course Backup. 1. Go into the course. 2. Click the Backup link either in the gear menu or the Administration b...
-
Hi ALL, Here I wrote a program for Void Method in java. /** * * @author Balamurgan M */ public class voidMethod { ...
-
Dear All, To backup files to Google Drive using PHP coding, you can use the Google Drive API and the Google Client Library for PHP. Here...
No comments:
Post a Comment