Arrays - Example 4

This program "decodes" a number entered in Roman Numerals. You are prompted to enter a number. The program then goes through it one character at a time (using a special function called charAt() which you haven't actually met yet - sorry!) and builds up a total in the variable called sum.

The program uses a state table to decode the number. It maintains a state, which is a number from 1 to 11. Depending on what character it comes across in the string entered by the user, it moves from one state to another. Another table shows what should be added to the total in each state and for each character in the input string.


Go back
Go Back