Hi vinit,
These Exception ( ArrayIndexOutOfBounds) occurs when the* index *used to get
a value in an Array is exceed the length o this array.
Well, to grasp the maining of these, try this in a new main java class :
public class OwnCommandLineArguments {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int[] Integerarray = new int[6];
for(int k=0;*k<10*;k++)
System.out.println(Integerarray[k]);
}
}
The Result of this is as follows:
0
0
0
0Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6
at OwnCommandLineArguments.main(OwnCommandLineArguments.java:13)
===> the lenght of Integerarray is 6 (from 0 to 5), and in the*
for*statement we have
*k<10 : * so at the sixth ( 6th) index
the Exception occurs.
But with if we change *k<10 to k<6 there is no
ArrayIndexOutOfBoundsException:
*
public class OwnCommandLineArguments {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int[] Integerarray = new int[6];
for(int k=0;*k<6*;k++)
System.out.println(Integerarray[k]);
}
}
Other things, In your programme you have the following statement:
*average = sum/Integerarraylength;*
If *Integerarraylength = 0 *here you have to surround these with ty{}
catch(){} block.
Else you will have an ArithmeticExeption.
So, Hope that can help.
Good luck.
Mohammed Jattioui
*
*
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en