+ 1
User input into if statement?
Does anyone know how to use the result of the user input in an if (user input > 16) { statement? Here is my code: https://code.sololearn.com/czXMyLYhM3XC/?ref=app It says that the â>â symbol is not suitable for the binary operation. Please help. Thanks.
7 Answers
0
Integer.parseInt() turns strings (text) into a number value e.g. â56â -> 56
.nextLine() always returns a string so in order to treat input like a number you need to turn it to such
+ 2
â You can write yourself if you complete this seriously
â Nicely explained with simple example
âĄhttps://www.sololearn.com/learn/Java/2205/
0
You have to store the input inside a variable...
String input = weight.nextLine();
Then to compare it to 16 you need to turn that string into an int (number)...
if (Integer.parseInt(input) > 16) {
// ...
}
0
TurtleShell what does the (Integer.parseInt) method here mean? my code doesnt seem to agree with it.
0
TurtleShell sorry to keep asking questions but the code is still returning an error. if you wouldnt mind reviewing it that would be great. thanks.
https://code.sololearn.com/czXMyLYhM3XC/?ref=app
0
Printing input instead of weight.nextLine() will do the job :)
0
TurtleShell thanks very much. fixed the issue!