Homework 4

Out: Tue 10 Feb 1998
Due: During Lab Session

Programming Assignment:

Write, compile and run the ConvertInt.java program to calculate convert a string to an integer, similar to the parseInt method of the Integer class.

   appomattox> java ConvertInt
   Value: 0123
   The value equals 123.
   appomattox>
You should write this program using the toDigit method found in the example program ToDigit.java. The method to convert is to start with an integer variable
   int v = 0 ;
and then convert each digit and update v according to:
    v = (10*v) + toDigit(s.charAt(i)) ;
You might want to take some time to consider why this works!

Don't worry about negative numbers or too much about badly formated numbers. Convert up until the first illegal character (toDigit returns -1) and stop.

Use PostIt to submit your homework. There are further instructions about how to do this.