
this program is accepting only integers as input but i want to modify it such that it can accept both integers and char. import java.util.*; public class Insertion1 { public static void insertion_srt(int array[],int n){ for (int j = 0; j < n; j++){ int i = j-1; int k = array[j]; while ((i>= 0) && (array[i] > k)){ array[i+1]=array[i]; i=i-1; array[i+1]=k; } } } public static void main(String a[]){ Scanner input=new Scanner(System.in); int array[]=new int[10]; int i;
System.out.println(" Selection Sort\n\n");
System.out.println("Values Before the sort:\n");
for(i = 0; i < array.length; i++){
array[i]=input.nextInt();
}
for(i = 0; i < array.length; i++){
System.out.println(array[i]);
}
insertion_srt(array, array.length); System.out.println("PAUSE");
}
}
System.out.print("Values after the sort:\n");
for(i = 0; i

Hi Friend,
Try the following code:
import java.util.*;
public class StringArraySelectionSort {
public static void main(String[] args)throws Exception{
Scanner input=new Scanner(System.in);
System.out.println("Enter number or char");
char[] array = new char[5];
for(int i=0;i<5;i++){
char ch=input.next().charAt(0);
array[i]=ch;
}
selectionSort(array);
for(int i = 0; i < array.length; i++){
System.out.print(array[i]+" ");
}
}
static char[] selectionSort(char[] array)
{
for (int i = 1; i < array.length; i++) {
int s = i-1;
for (int j = i; j < array.length; j++) {
if (Character.toString(array[j]).compareTo(Character.toString(array[s])) < 0) {
s = j;
}
}
char temp = array[i-1];
array[i-1] = array[s];
array[s] = temp;
}
return array;
}
}
Thanks