Table 3 Exercises

For these exercises, we use and (&&), or (||) to combine multiple tests in an if-test. The baby fields are "name", "rank", "gender", "year".

1. Write code to print all the rows where the name starts with "X" or the name starts with "Y". Suggestion: when you have code running, look carefully at the output. Does the output look reasonable? For this problem for example, do you see a mix of names starting with either "X" or "Y"? It's nice if you can quickly check the correctness of your code right when you run it.


2. Write code to print all the rows where the name starts with "B" and the name ends with "a". As above, glance at the output to check that it looks right.


3. Write code to print all the rows where the name ends with "i" and the gender is "boy". Reminder of "boy" test: row.getField("gender") == "boy"


4. Write code to print all the rows where the rank is <= 10 and the gender is "boy" (i.e. the top 10 boy names).