The array indexes in Java start from 0
and go to array.length - 1
. So change the loop to for(int i=0;i<a.length;i++)
More Related Contents:
- Why Java Only Allows String[] args as Main method Argument? [duplicate]
- Type mismatch: cannot convert from double to double[]
- I have a function in java which may have bug and I can not find it [closed]
- How do I determine whether an array contains a particular value in Java?
- How do I reverse an int array in Java?
- Arrays.asList() not working as it should?
- How to convert jsonString to JSONObject in Java
- How do I remove objects from an array in Java?
- Array or List in Java. Which is faster?
- A quick and easy way to join array elements with a separator (the opposite of split) in Java [duplicate]
- How to convert an ArrayList containing Integers to primitive int array?
- How to supply value to an annotation from a Constant java
- What is this: [Ljava.lang.Object;?
- Creating an array of objects in Java
- Quickest way to find missing number in an array of numbers
- Lambda expression to convert array/List of String to array/List of Integers
- How to get String Array from arrays.xml file
- Passing directly an array initializer to a method parameter doesn’t work
- Java two varargs in one method
- Java: Reading integers from a file into an array
- How are arrays implemented in java?
- Easiest way to convert a Blob into a byte array
- Explanation on Integer.MAX_VALUE and Integer.MIN_VALUE to find min and max value in an array
- Interview question – Search in sorted array X for index i such that X[i] = i
- Convert byte[] to Base64 string for data URI
- Java Iterate Bits in Byte Array
- How to convert JSONArray to List with Gson?
- In Java, when is the {a,b,c,…} array shorthand inappropriate, and why?
- Array with UserType in Hibernate and PostgreSQL –> MappingException
- Java generics and array initialization