r/learnjava • u/ThatGuyThatIsNotReal • Sep 25 '21
Calling all numbers?
I would like to call all numbers to restrict the input to be only numbers? What is the best way to do this?
0
Upvotes
1
u/Qudiza Sep 25 '21
This might be helpful: https://stackoverflow.com/questions/23905985/validation-input-to-be-string-only-and-numbers-only-java
It depends on your special case wich will be the best solution. Regex is good to use for it, If your 'input' ist a Stream from Scanner, it is possible to check for int or Double for example. You could also 'scan' the next Numbers, when you have "Mixed Input" if that possible to understand.
If this doesn't help, please describe your aim/Problem more detailed.
5
u/NautiHooker Sep 25 '21
We will need more information. What exactly are you trying to do? What do you mean by "calling" all numbers?