What does the keyboard send to your program when you type the following:
1234
The characters '1' , '2' , '3' , and '4' .
The keyboard sends character data to the computer, even when the characters look like numbers. And the program sends characters to the monitor, even when it has calculated a numerical result. (Actually, characters are not sent directly to the monitor. They are sent to the graphics card which converts them into a video signal which is displayed on the monitor.)
If your program does arithmetic,
the input characters
will be converted into one of the primitive numeric data types.
This is done using Scanner
.
Then a result is calculated using arithmetic with the numeric data.
The result must then converted to character data before it is sent to the monitor.
This is done using a method of System.out
.
Have you already used System.out
?