Thinking in Java Fourth Edition Bruce Eckel Chapter 4 Exercise 16

Exercise 16: Create an array of String objects and assign a String to each element. Print the array by using a for loop.

public class StringArrayEx16
{
    public static void main(String[] args)
    {              
        String[] s = { "one", "two", "three", };       
        for(int i = 0; i < s.length; i++)
            System.out.println("s[" + i + "] = " + s[i]);
    }
}

Output:

Leave a Reply

Your email address will not be published. Required fields are marked *