Digits as Input

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   hear noise   go to next page

Answer:

Yes. Collecting characters and allowing the user to edit them is done by the operating system. The user signals that the line is complete by hitting "enter" and sending the charaters to the program.

Digits as Input

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?