Results 1 to 2 of 2
  1. #1
    chuckypalumbo is offline Member
    Join Date
    Apr 2011
    Rep Power

    Default Fill in the blank code for arrays


    I'm new to the forum and the online university I go to has fill in missing code type assignments. I've spent a ton of hours this week trying to learn arrays and how they work, but I'm stuck on the first part of our assignment and am not sure what code to fill it in with. Any help and explanation would be appreciated.

    // Application Reverse reads numbers into an array
    // and prints them out in reverse order.
    import java.util.Scanner;
    public class Reverse
    public static void main(String[] args) throws IOException
    final int MAX = 10;
    Scanner inFile =
    new Scanner(new FileReader("Reverse.dat"));
    int[] numbers;
    numbers = new int[MAX];

    int value;
    int index;
    for (index = 0; index < numbers.length; index++)
    // FILL IN Code to read value
    // FILL IN Code to store value into numbers

    for (index = MAX - 1; index >= 0; index--)

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Richmond, Virginia
    Blog Entries
    Rep Power


    Welcome to the forums, and I hope I can help you out.

    Lets first try to think about what this does
    Java Code:
    for (index = 0; index < numbers.length; index++)
    // FILL IN Code to read value
    // FILL IN Code to store value into numbers
    This is going to repeat some task x times, in this case x is equal numbers.length. It is going to start at 0, and go to numbers.length - 1, which is how array indexing works.

    Java Code:
    int[] x = {1, 2, 3, 4, 5}; //length of 5
    x[0] == 1
    x[1] == 2
    x[2] == 3
    x[3] == 4
    x[4] == 5
    So you are going to be evaluating the block numbers.length times. You want to first receive input from the user and then assign the index to that value.

    Lets see what you can come up with before we go any further. I suggest you check out the following link: Using a scanner to read a file

    Post up what you come up with and please use code tags.


Similar Threads

  1. Blank screen
    By dewitrydan in forum New To Java
    Replies: 14
    Last Post: 08-12-2010, 05:19 PM
  2. 2d Arrays Code help!
    By Meta in forum New To Java
    Replies: 12
    Last Post: 04-04-2010, 06:49 AM
  3. Blank space
    By sandy1028 in forum New To Java
    Replies: 1
    Last Post: 04-21-2009, 10:00 AM
  4. Replies: 2
    Last Post: 11-18-2008, 10:44 PM
  5. Help needed with java arrays code
    By d24706 in forum New To Java
    Replies: 2
    Last Post: 03-07-2008, 01:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts