Code is copied!
Define a class to accept 10 characters from a user. Using bubble sort technique arrange
them in ascending order. Display the sorted array and original array.
Solution:
,
import java.util.*;
class question4
{
public static void main(String args[])
{
char a[] = new char[10];
Scanner sc = new Scanner(System.in);
System.out.println("Enter 10 characters");
for(int i=0; i< a.length; i++)
{
a[i] = sc.nextLine().charAt(0);
}
System.out.println("ORIGINAL ARRAY");
for(int i=0; i< a.length; i++)
{
System.out.print(a[i] +" ");
}
System.out.println();
int n=a.length;
{
for(int i =0;i< n-1;i++)
{
for(int j=0; j< n-i-1; j++)
{
if(a[j]>a[j+1])
{
char t = a[j];
a[j] = a[j + 1];
a[j+1] = t;
}
}
}
System.out.println("SORTED ARRAY");
for(int i=0; i< a.length; i++)
{
System.out.print(a[i] +" ");
}
}
}
}