I attempted to create a calculator, but I can not get it to work because I don't know how to get user input.
How can I get the user input in Java?
I attempted to create a calculator, but I can not get it to work because I don't know how to get user input.
How can I get the user input in Java?
It is very simple to get input in java, all you have to do is:
You can get user input using
BufferedReader
.It will store a
String
value inaccStr
so you have to parse it to anint
usingInteger.parseInt
.Here, the program asks the user to enter a number. After that, the program prints the digits of the number and the sum of the digits.
Can be something like this...
To read a line or a string, you can use a
BufferedReader
object combined with anInputStreamReader
one as follows: