+ 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

1st Mar 2019, 9:19 PM
ZdzichPych
ZdzichPych - avatar
16 Answers
+ 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?
1st Mar 2019, 11:04 PM
Denise Roßberg
Denise Roßberg - avatar
+ 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.
1st Mar 2019, 9:22 PM
Rowsej
Rowsej - avatar
+ 6
So product is just an empty string?
1st Mar 2019, 9:29 PM
Rowsej
Rowsej - avatar
+ 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
4th Mar 2019, 5:54 PM
Denise Roßberg
Denise Roßberg - avatar
+ 6
ZdzichPych no problem :)
4th Mar 2019, 7:43 PM
Denise Roßberg
Denise Roßberg - avatar
+ 5
Hmm... strange. I’m sorry, but I don’t know how to overcome that problem.
1st Mar 2019, 9:48 PM
Rowsej
Rowsej - avatar
+ 4
Denise, thank you very much for your time and help!
4th Mar 2019, 7:33 PM
ZdzichPych
ZdzichPych - avatar
+ 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();
1st Mar 2019, 9:25 PM
ZdzichPych
ZdzichPych - avatar
+ 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
1st Mar 2019, 9:32 PM
ZdzichPych
ZdzichPych - avatar
+ 3
Thank you all the same
1st Mar 2019, 9:54 PM
ZdzichPych
ZdzichPych - avatar
+ 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
2nd Mar 2019, 7:32 AM
ZdzichPych
ZdzichPych - avatar
+ 3
ZdzichPych I changed the split: String[] steps = yourRecipe.split(" "); Try my code to see if you get your expected output.
2nd Mar 2019, 3:07 PM
Denise Roßberg
Denise Roßberg - avatar
+ 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.
2nd Mar 2019, 8:28 PM
Denise Roßberg
Denise Roßberg - avatar
+ 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.
2nd Mar 2019, 8:22 PM
ZdzichPych
ZdzichPych - avatar
+ 2
Denise, thank you, I'll try it here
3rd Mar 2019, 9:32 AM
ZdzichPych
ZdzichPych - avatar
+ 2
Denise, may be it is because of all those spaces, but I'm getting a compilation error on SoloLearn
4th Mar 2019, 3:55 PM
ZdzichPych
ZdzichPych - avatar