Sun Java Solaris Communities My SDN Account Join SDN
 
Tutorials & Code Camps

jGuru: Using Java Arrays

 

by jGuru

[Help | API Docs | Short Course| Exercises]

For this exercise you will create and initialize an array of integers and an array of String objects.

[If you are using IBM's VisualAge for Java for this exercise, then use the scrapbook to type and test your code (without a main method etc...), thus, avoiding the need to fill in the skeleton code, compile, and run from the command line.].

Prerequisites

  • None.

Skeleton Code

Tasks

  1. Make an array of 5 integers.

  2. Use a for loop to set the values of the array to the index plus 10.

  3. Use a for loop to print out the values in the array.

  4. Make an array of strings initialized to Frank, Bob, and Jim using the variable initializer syntax.

  5. Use a for loop to print out the strings in the array.

  6. Set the last element of the array to Mike.

  7. Print out the last element in the array.

Where help exists, the task numbers above are linked to the step-by-step help page.

Solution Source

Demonstration

If you execute Arrays from a command line, the output should be similar to the following:

10
11
12
13
14
Frank
Bob
Jim
Mike

Next Exercise

Exercises

Short Course

Copyright 1996-2000 jGuru.com. All Rights Reserved.