
May 12th, 2007, 04:15 PM
|
|
Contributing User
|
|
Join Date: Mar 2006
Posts: 60
Time spent in forums: 21 h 3 m 50 sec
Reputation Power: 3
|
|
Can you post your code and show us where you are stuck? It's hard to help if we don't know what you need help with.
Here is an example on how you make arrays:
Code:
int[] myArray = new int{1,2,3,4,5};
// 'int[]' specifies the type of data you want on the array
// 'myArray' is the name you give to your array
// 'new int' creates the object
// '{1,2,3,4,5}' are the elements in the array, in this case there are five
An alternate way to create the same array is:
Code:
int[] myArray2;
myArray2 = new int[5];
myArray2[0] = 1;
myArray2[1] = 2;
myArray2[2] = 3;
myArray2[3] = 4;
myArray2[4] = 5;
// 'int' and 'myArray2' are the same as before
// 'new int[5]' creates the array with size five
// 'myArray[y] = x' adds x number to the corresponding array position
// Note that the array index starts from 0.
I guess in your program you will be comparing numbers from 2 arrays or something, so if you want to compare specific elements on two arrays, you do something like:
Code:
if(myArray[0] == myArray2[0]){
System.out.println("match");
}
else
System.out.println("No match");
To compare all the items, you would use loops.
|