public class BoolArray {

    public static void main (String [] args) {
	boolean [] b = new boolean [3];
	
	// print out b (all false values):
	System.out.println("array b before assignment:");
	for (int i = 0; i < b.length; ++i) {
	    System.out.println("b[" + i + "] = " + b[i]);
	}
	
	// change b:
	for (int i = 0; i < b.length; i = i + 2) {
	    b[i] = !b[i];
	}

	// print out b:
	System.out.println("array b after the change:");
	for (int i = 0; i < b.length; ++i) {
	    System.out.println("b[" + i + "] = " + b[i]);
	}
    }

}

This is an example from CSci 1211 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.