Results 1 to 2 of 2
- 05-02-2011, 01:04 AM #1
Member
- Join Date
- Apr 2011
- Posts
- 1
- Rep Power
- 0
Fill in the blank code for arrays
Hi,
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;
import java.io.*;
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--)
System.out.println(
inFile.close();
}
}
- 05-02-2011, 01:17 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Welcome to the forums, and I hope I can help you out.
Lets first try to think about what this does
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:for (index = 0; index < numbers.length; index++) { // FILL IN Code to read value // FILL IN Code to store value into numbers }
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.Java Code:int[] x = {1, 2, 3, 4, 5}; //length of 5 //indexes x[0] == 1 x[1] == 2 x[2] == 3 x[3] == 4 x[4] == 5
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.
[code]
YOUR CODE HERE
[/code]
Similar Threads
-
Blank screen
By dewitrydan in forum New To JavaReplies: 14Last Post: 08-12-2010, 05:19 PM -
2d Arrays Code help!
By Meta in forum New To JavaReplies: 12Last Post: 04-04-2010, 06:49 AM -
Blank space
By sandy1028 in forum New To JavaReplies: 1Last Post: 04-21-2009, 10:00 AM -
Can someone please help fix this code so the program works? (2D arrays)
By busdude in forum New To JavaReplies: 2Last Post: 11-18-2008, 10:44 PM -
Help needed with java arrays code
By d24706 in forum New To JavaReplies: 2Last Post: 03-07-2008, 01:11 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks