Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Integer Arrays!
#1
I recently made a video tutorial on integer arrays, and some people may just want to copy/paste the code for their own purposes, so here it is, fully commented!
[code2=java]public class arrayTutorial { //Create the class

public static void main(String[] args){ //Create the main method (This is what gets executed)

int arrInt[] = new int[5]; //Create a new integer array with 5 slots
//Note: Indices start from 0
arrInt[0] = 1; //Tell the first slot (index) in the array to have a value of 1

int i = 1; //Give i a value of 1
while (i <= 4){ //If i is less than 5
arrInt[i] = i+1; //Assign the corresponding slot of the array (i) a value of 1 + i; so if i is 2, the 3rd slot of the array would be filled with 2+1, which is 3.
i++; //Increase the value of i by one

}
System.out.println(arrInt[0]+ " " + arrInt[1] + " " + arrInt[2]+ " " + arrInt[3] + " " + arrInt[4]); //Output all the slots in the array in string form (seperated by spaces)


}

}[/code2]

Basically, what I am doing here, is creating a new integer array with 5 slots, using a while statement to fill the 5 slots, and displaying each slot, separated by a space.

Hopefully this helps anyone actually doing Java (As I know this forum is mostly vb.net based)
My Blog | My Setup | My Videos | Have a wonderful day.


Messages In This Thread
Integer Arrays! - by brandonio21_phpbb3_import2 - 10-02-2011, 08:56 PM
Re: Integer Arrays! - by WitherSlayer - 01-03-2013, 05:58 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)