0
How to arrange the word as per alphabetical order based on the first letter of the word in the sentence?
Without using compareTo() function and swapping using two loop. Need simple way rather than complex.
7 ответов
+ 1
Done successfully by me
0
Hello shubham kumar
You can get the first letter of a string with .charAt(0). 0 is the first index.
String s = "hello";
char firstChar = s.charAt(0);
If you have two words you can use an if statement:
if(word1.charAt(0) > word2.charAt(0){
//swap words
}
So your task is like sorting a char array. I suggest you to have look into the bubble sort algorithm.
https://www.sololearn.com/learn/649/?ref=app
0
Hello Denise RoBberg,
I tried this way but
Again the trouble is after getting word of sentence in an array form using split (" ") function generates difficulty to set for loop and execute character extraction of that word and analyse and set that word as per that character in ordered sequence.If you help me through a code,I will be thankful to you.I tried but it failed.
0
Hello shubham kumar
Can you show me what you have tried so far?
0
Hello Denise RoBberg
https://code.sololearn.com/ckE1POZU7rMv/?ref=app
0
Do you still need help?
0
https://code.sololearn.com/cmG78Ee7fsll/?ref=app
Follow this for easy