when i am running the program and when it asks for the user input i enter 3 but it takes only 2 inputs if you are not getting run this code on your device
Run this code you will get what i want to ask
Hello subham
i hope you know know when to use next() and when to use nextline().
If you write “Hello World” in the console:
By using Scanner.Next() you will get the word “Hello” as the input value and you won’t get the next word.
If you use Scanner.NextLine() instead, you will get the whole line.
So use next() while you take input your code will take 3 inputs.
if you still face any issue please let me know
i dont know this concept
can you fix error in my code and explain it to me
Hi Shubham
Your code is correct but you just need to implement one more logic in your code which is
if a string is present completely as a prefix in another string, then string with longer length should come first. Eg bat, batman are 2 strings and the string bat is present as a prefix in Batman - then sorted order should have - Batman, bat.
and for that you can use this logic:-
for (int i = 0; i < n - 1; i++) {
if (words[i + 1].contains(words[i])) {
String temp = words[i];
words[i] = words[i + 1];
words[i + 1] = temp;
}
}
I Hope you will understand and if you still face any issue Please let me know I will Share code with you.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.