xhtml
 

Exercise 9: Parsing

The short documentation for the parseInt method in the Integer class tells us that it takes a String as its argument and returns an int as its result, which is exactly what we want for converting input text to numbers. Here is a program which shows how to use the parseInt method. It takes two arguments which are assumed to be numbers, converts them from text, and prints out their sum.

Your task is to adapt the program to add up three numbers instead of two.

The program won't be robust, partly because it doesn't check that three numbers are given, and partly because it doesn't check that the numbers are properly formed. You needn't worry about this yet.

Any kind of conversion from text to something internal is called parsing and is complicated because of the possible variations and errors which might have to be dealt with in the text.

Hint


Back