write a program which can take a string and then arrange it according to word length. check the description. send the code, pls | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

write a program which can take a string and then arrange it according to word length. check the description. send the code, pls

In a online test of SAP, there is question, like "By using any programming language write a program which can take a string and then arrange it according to word length, that means if a string is "hello i am a programmer", so the output is " ' i a am hello programmer ' "

2nd Dec 2018, 5:53 AM
Priyajit Nayak
Priyajit Nayak - avatar
4 Answers
+ 7
java approach 1) Split string using split(" ") 2) Get length of each word 3) Arrange in asending order of word length
2nd Dec 2018, 5:58 AM
Rstar
Rstar - avatar
+ 2
-Take the input -Split the input into array with whitespace as separator -Do the sort like normal, use any sorting algorithm that is easy for you to write -Merge the array -Output If you ask for a code try to find it in code playground. I dont think anyone would write an entire program for you in QA.
2nd Dec 2018, 6:01 AM
Taste
Taste - avatar
+ 2
Have you tried something? Show us your attempt, as then it will benefit you more. Simply copying the code does not help. For solving the issue, you can first store the words in individual strings, and then sort the resultant array of strings. Then join them back together to form a single string.
2nd Dec 2018, 6:04 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 2
basically I know so many languages, but I love to do program in C language, so after that test I tried so many procedures, like first split the words and then find out the length of first one and then check another one length and compare between them and put the smaller one into a final string, but I can not complete the program due to lack of logic, I think I can do it in JAVA & python, bcz there is a special len() function. ok thank you everyone to give me suggestions.
19th Dec 2018, 5:13 PM
Priyajit Nayak
Priyajit Nayak - avatar