This is a program to sort every word in a sentence in ascending order.
import java.util.Scanner;
import java.util.Arrays;
class sorteveryword
{
void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string");
String str=sc.nextLine();
String arr[]=str.split(" ");
int l=arr.length;
for(int i=0;i<l;i++)
{
String w=arr[i];
char ch[]=w.toCharArray();
Arrays.sort(ch);
System.out.print(ch+" ");
}
}
}
This code seems perfect to me but when I am printing something it is showing this output.
Enter the string
ab bc
[C@55fba33b [C@51c42d5c
I really don't know why this is happening.
Please help. And also please provide an alternative.
I want the output as
Enter the string
your eyes
oruy eesy