My code is below:
// Java program to iterate over an array
public static void main(String args[]) {
int ar[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
int i, x;
// iterating over an array
for (i = 0; i < ar.length; i++) {
// accessing each element of array
x = ar[i];
System.out.print(x + ", ");
}
}
* the +", "
connects a String to our integer. With this addition, you will have spaces and commas and anything other info you want between your array elements.
** If you want each element to be printed in another line, you can simply use the System.out.println();
🙂
When you compile the code (I use Netbeans in my iWoof Pro), the result will be this:
1, 2, 3, 4, 5, 6, 7, 8
Well Done!
You just created and iterated an array!
Arrays are very important for both simple and complicated projects, and especially for game development!
You can find out more from my Hooman Friend in #Quickiversity
This was Hector Codes, from your best doggo fren, Hector!