Skip to main content
IBM 
ShopSupportDownloads
IBM HomeProductsConsultingIndustriesNewsAbout IBM
Java Language EssentialsDownload tutorial zip fileEmail this tutorial to a friend
Main menuSection menuGive feedback on this tutorialPrevious panelNext panel
Exercises
  


3. Using Java Arrays: Help page 9 of 31




  • Task 1

    Make an array of 5 integers.


    Define the array, but don't assign anything to it.

  • Task 2

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


    To access the elemetns of the array, use the loop index, as in this example:

    
    for(int i = 0; i < 5; i++) {
        myarray[i] = 0;
    }
    
  • Task 3

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


    To print a string, do this:

    
    System.out.println("msg");
    
  • Task 4

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


    The initalization expression should be:

    
    { "Frank", "Bob", "Jim" }
    
  • Task 5

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


    This is similar to printing out integers.

  • Task 6

    Set the last element of the array to Mike.


    The string literal here should be "Mike"

  • Task 7

    Print out the last element in the array.


    The last index of an array is always one minus the length of the array.


copyright 1996-2000 Magelang Institute dba jGuru


Main menuSection menuGive feedback on this tutorialPrevious panelNext panel
PrivacyLegalContact