July 7, 2008

Chapter: Initialization and Cleanup

Create an array of String objects and assing a String to each element. Print the array by using a for loop

I also demonstrate an alternative way to print the array.

In Java:
package chapter.initialization;

import java.util.*;

public class Exercise16 {

public static void main(String[] args) {

String[] stringArray = new String[] { "aaa", "bbb", "ccc", "ddd" };

for (String x : stringArray)


In Python:
stringArray = ("aaa", "bbb", "ccc", "ddd")

for x in stringArray:
print x

print stringArray

In Lisp:
(setq string-array '("aaa" "bbb" "ccc" "ddd"))

(loop for x in string-array do (print x))

(print string-array)