go to previous page   go to home page   go to next page hear noise

Answer:

Yes.


Digits as Input

Collecting characters from the keyboard is done by the operating system. While this is going on, the Java program is suspended. The user can edit the line, and then hit "enter" to signal that it is complete. Only then does the Java program see the characters and resume execution.

Here is another run of the program:

Enter the data:
Columbus sailed in 1492.
You entered:Columbus sailed in 1492.

Notice that the characters '1', '4', '9', and '2' were read in and written out just as were the other characters.

Now consider yet another run:

Enter the data:
1492
You entered:1492

Nothing special here. The '1', '4', '9', and '2' are just characters. If you want the user to enter numeric data, your program must convert from character data to a numeric type.


QUESTION 11:

What primitive type should normally be used to hold integer data?