As Garth shared, it's difficult for anyone to help if you don't point the line you are getting error from.
Now, my suspects:
#1
for(int i=0; i<a.length; i++)
{
for(int j=i+1; j<a.length; j++)
{
if(a[i]>a[j])
Believe you are trying a selection sort here. Given the values, at the last value of i, j would go out of bound and can raise an error.
Example:
a = "abcd";
i=> 0,1,2,3
j=> 1,2,3,4
a[4]
Fix:
for(int i=0; i<a.length-1; i++)
{
for(int j=i+1; j<a.length; j++)
{
if(a[i]>a[j])
#2
for(int i=0; i<a.length; i++)
{
System.out.println(a[i]);
if(a[i]>a[i+1])
Here again, with the last value of i, i+1 will bomb.
Example:
a = "abcd";
i=> 0,1,2,3
i+1 => 1,2,3,4
a[4]
Fix:
for(int i=0; i<a.length-1; i++)
{
System.out.println(a[i]);
if(a[i]>a[i+1])
Try out!