CSci 2101 Data Structures: Lab 12

Problem 1: smallest elements in a 2D array

Write a program that initializes a two-dimensional array of integers and prints out the following: Assume that the array doesn't have any missing rows and all rows are of the same length. You may use this code to get you started.

Problem 2: a checkered pattern

An array is a "checkered pattern" if every element a[i][j] is even if i + j is even, and is odd otherwise. For instance, the following array is a checkered pattern, assuming that a[0][0] is at the left upper corner:

4 3 2 7 0
9 2 5 6 3
The following array is not:

3 4 
9 2 
Write a method

public static boolean isCheckered(int [][] arr)
which returns true if the array is a checkered pattern and false otherwise. Again, you may assume that the array is a normal n-by-m matrix, without any missing elements or other anomalities.

Extra credit, only if you have time: Write this method using only for-each loops. Please submit both versions of the method (use a different name for the new one).


This is a lab from CSci 2101 course.

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.