Design a program to create an array of strings, size should be entered by the user(between 5 to 20). And sort the string array in ascending order using the Bubble sort technique.
For more programs
https://wordpress-343193-1101484.cloudwaysapps.com/count-words-start-and-end-with-a-vowel
import java.util.*;
class StringLinearSearch
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the size of array between 5 to 20");
int n=sc.nextInt();
String list[]=new String[n];
for(int i=0;i<n;i++)
{
System.out.println("Enter words");
list[i]=sc.next();
}
int len=list.length;
for(int i=0;i<len-1;i++)
{
for(int j=0;j<len-1-i;j++)
{
if((list[j].compareTo(list[j+1]))>0)
{
String temp=list[j];
list[j]=list[j+1];
list[j+1]=temp;
}
}
}
System.out.println("Sorted array");
for(int i=0;i<len;i++)
{
System.out.println(list[i]);
}
}
}Output:
Enter the size of array between 5 to 20
5
Nadiad
Madras
Bombay
Chennai
Agartala
Sorted array:
Agartala
Bombay
Chennai
Madras
Nadiad