Thinking in Java Fourth Edition Bruce Eckel Chapter 4 Exercise 21

Exercise 21: Create an enum of the least-valuable six types of paper currency. Loop through the values( ) and print each value and its ordinal( ).

public class EnumEx21
{
    public enum Bills
    {
        ONE, FIVE, TEN, TWENTY, FIFTY, HUNDRED
    }
    public static void main(String[] args)
    {
        for(Bills b : Bills.values())
            System.out.println(b + ", ordinal " + b.ordinal());
    }  
}

Output:

Leave a Reply

Your email address will not be published. Required fields are marked *