+ 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 ответов
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!