Showing posts with label Array. Show all posts
Showing posts with label Array. Show all posts

Tuesday, November 23, 2010

Array of arrays

You have worked with only one dimensional arrays up to now, that is arrays that use a single index.

Suppose that you have a fanatical interest in the weather and you are intent on recording the tempertature at
10 separate geographical throughout the year once you have sorted out the logidtics of actually colleting this
information you can use an array of 10 elements corresponding to the number of locations where each of these elements in an array of 365 elements to store the temperature values you would declare this array with the statements.
                                  float [] [] temperature = new float [10] [365]; 


hope this will be very useful for your programing knowledge

Wednesday, November 17, 2010

Accessing array elements in Java

  int[] primes=new int[10];       // Creating a new array object 

You can refer to an array by using the array name followed by the element's  index value closed in between sqyare brackets.You can specify an index value by ant expression that produce  zero or possitive result of type int . If you use a value type of long as an index, you will get an error message from the compiler, if  you calculate of an index uses long variables and the result is of type long, you will need to cast it to type int.

The maximum index value for an array is one less than the number of element in the array. JAVA checks that the index values you see are valid.if you use an index value that is less than 0, or greater than the index value for the element in the array an exception will be thrown. (Index out of bound exception)

The prime array which was taken as an example above is sometimes referred to as an one dimensional error because each of its elements is referenced using one index-running from 0 to 9 in this case......