![](https://simplycoding.in/wp-content/uploads/2020/04/Java-Program-on-Bubble-Sort.jpg)
Java Program on Bubble Sort
- Categories Java, Arrays in Java, Arrays
Write a program to input twenty names in an array. Arrange these names in descending order of alphabets using the bubble sort technique.
import java.util.Scanner; public class ArrangeNames { public static void main(String []args) { String a [] =new String [20]; Scanner scan=new Scanner(System.in); System.out.println("Please enter the twenty names"); for (int i = 0; i <= 19; i++) { a [i]= scan.next(); } String t; for (int i=0; i<19; i++ ) { for (int j = 0; j < 20 -i-1; j++) { if (a[j].compareTo (a[j+ 1]) >0) { t = a[j] ; a[j] =a[j+1]; a[j+1]= t; } } } System.out.println("Sorted element are:"); for (int k=19; k> 0; k--) { System.out.println(a[k]); } } }
You may also like
![Single Linked List Programs in Java Single Linked List Programs in Java](https://simplycoding.in/wp-content/uploads/2021/07/Single-Linked-List-Programs-in-Java-300x200.png)
Single Linked List Programs in Java
28 August, 2021
![Implementing Stack using Array in Java Implementing Stack using Array in Java](https://simplycoding.in/wp-content/uploads/2021/08/Implementing-Stack-using-Array-in-Java-300x200.png)
Implementing Stack using Array in Java
28 August, 2021
![Constructor Programs Constructor Programs](https://simplycoding.in/wp-content/uploads/2021/06/Constructor-Programs-300x200.jpg)
Constructor Programs
3 July, 2021