CS 310, Object-Oriented Programming with Java

Quiz 4, 14 February 2008


  1. Even though multidimensional arrays are implicitly implemented as ragged arrays, it may occasionally be useful to explicitly implement them as ragged arrays. Explain the main reason for doing so.


    If fixed-length row sizes would result in significant wasted space at the end of the rows, it makes sense to implement a multidimensional array as an explicit ragged array, sizing each row to fit (Ragged Arrays, page 90 (7th ed.) or 102 (8th ed.)).

    Examples of such circumstances include upper or lower triangular matrices, or storing a text file in a matrix (the rows would have to be sized to contain the longest line, which wastes space at the end of the rows for lines shorter than the longest).

  2. Why shouldn't I use a double or float to represent money?


    A floating-point number is incapable of exactly representing some decimal numbers, such as 0.01 (Floating-Point Types, page 40 (7th ed.) or 42 (8th ed.)).


This page last modified on 31 March 2008.