Practice Questions (Code Writing)

Lists & Sets

CodeCheck Questions

  1. You want to collect all “short” words in an array of words, that is, words with at most three characters. Since you don’t know in advance how many short words there are, collect them in an array list, not an array.

    For example, if you are passed an array containing the words

    “Mary”, “had”, “a”, “little”, “lamb”

    you would return an array list containing the words

    “had”, “a”

    Solve it here

  2. You want to pick a particular “short” word in an array of words, that is, words with at most three characters.

    For example, if you are passed an array containing the words

    “Mary”, “had”, “a”, “little”, “lamb”

    and you are asked to return the second short word, you would return

    “a”

    Solve it here

  3. You are given a class similar to the TicTacToe board in Section 7.6, but the board can have more than 3 rows and columns.

    Your task is to complete a method that fills the two diagonals with asterisks, like this:

    *      *
     *    * 
      *  *  
       **   
       **   
      *  *  
     *    * 
    *      *
    

    Solve it here

  4. You are given a class similar to the TicTacToe board in Section 7.6, but the board can have more than 3 rows and columns.

    Your task is to complete a method that fills the four borders (that is, all cells at the left, right, top, and bottom boundary) with asterisks, like this:

    ********
    *      *
    *      *
    *      *
    *      *
    *      *
    *      *
    ********  
    

    Solve it here

Back to Top