Sunday, January 2, 2011

Java Tutorial #17

0
Application of Array in Tables
Consider this program.


In the example, I declare a String array (Array Name and Nick). I created a loop that will automatically go to each item in the array. This will count how many items in each array.
Here's How:  First, create a variable that will serve as the index. Initialize its value to 0. Second, set a condition that this value is greater than the size of the array. The keyword .length is a special java function reserve for the counting the elements inside an array (initializer).
Now, index=0, and it is greater than the elements in the array "Name". The next step is to increment the variable index. So, index=0, will count from 0 to “how many elements in the array "Name", and will increment 1 to its value (the values will increase one value).
The next step is outputting the index (plus a tab space) and the value of the array. Since the variable "index" is created to count how many elements in the array are, we can now use it as index  of the array "Name". What the for loop does is.. it will go through each elements of the array (it will take all of the elements inside that array). IT WILL OUTPUT THIS ONE. I UNDERSTAND YOU IF YOU DON'T UNDERSTAND THIS ONE. I THINK THIS IS ONE OF THE DIFFICULT PARTS OF JAVA AND ALSO THE C++. AND I PERSONALLY HATED THIS PART. SO, I DON'T SPEND MORE WORDINGS TO IT. I PERSONALLY UNDERSTAND IT. I TRIED MY BEST TO EXPLAIN IT FOR SOME DUMMY OUT THERE.



No Response to "Java Tutorial #17"

Post a Comment