+ 5
Could you find a problem with user's input in my code?
Could you please find out what is the root of the problem with user's input in my code? I usually use Scanner for this purpose, yet, this particular code asks for input only once istead of twice, and I have no idea what has caused such a behaviour. (The code is running on NetBeans without errors, still, it ommits a line for inserting the second input) https://code.sololearn.com/c63OFGDk6sDp/?ref=app
16 odpowiedzi
+ 6
ZdzichPych
https://code.sololearn.com/c62Iddn7mJFH/?ref=app
I made a copy of your code to remove all white spaces in it. I think you copied it from your IDE and copied unwanted characters (looks like white spaces but gives compiler error)
* package recipe don't work (I don't know why)
* Input:
Recipe --> Enter
Product
fish Enter
fish
--> output: found fish
But I don't know what you expect if you input this:
fish, pommes, salad (enter)
fish
Only fish or the whole recipe?
+ 7
How the SoloLearn compiler works, is the code is compiled on a server, and the input is only asked once at runtime, because it needs to send that to the server as input. But if you test it on a real Java compiler, it will work perfectly.
+ 6
So product is just an empty string?
+ 6
Yes. Thats why I made a copy for you without these spaces. See my post from 3.2.
https://code.sololearn.com/c62Iddn7mJFH/?ref=app
+ 6
ZdzichPych no problem :)
+ 5
Hmm... strange. I’m sorry, but I don’t know how to overcome that problem.
+ 4
Denise, thank you very much for your time and help!
+ 3
Rowsej, thank's for your answer! I apologise for not specifying the issue, the code is executed on NetBeans. It doesn't generate any errors, it just ommits the line String product = in.nextLine();
+ 3
I want a user to write a product and then use this string, but it compiles as if there is no such line at all... As a result, while executing control statement, it shows that there is no such a product, so I think this is actually an empty string as you've said
+ 3
Thank you all the same
+ 3
Denise, thank you for your answer! Yes, I've copied it from NetBeans, it is a bit difficult for me to write codes on my phone with its small display, yet, copying leads to all that spaces. This code was just a sort of practising some String methods, that is why it is silly. However, I wanted a user to insert a recipe, then, any product, divide an entire string of recipe into steps, and show a user the steps in which this product is used
+ 3
ZdzichPych I changed the split:
String[] steps = yourRecipe.split(" ");
Try my code to see if you get your expected output.
+ 3
ZdzichPych on sololearn:
Enter the recipe: pepper salt whatever then push enter
enter your product
if the product is used in the recipe I get all products of the recipe.
+ 2
Denise, thank you for yor suggestion. I'm afraid, it doesn't give right output. I've tried it on NetBeans and the line asking for a product still doesn't work. Additionaly, I suppose the code now gives the sentence "There is no such product..." the number of times equal to the number of sentences created by splitting.
+ 2
Denise, thank you, I'll try it here
+ 2
Denise, may be it is because of all those spaces, but I'm getting a compilation error on SoloLearn