Arrays in Java are indexed from 0
to length - 1
, not 1
to length
, therefore you should be assign your variable accordingly and use the correct comparison operator.
Your loop should look like this:
for (int counter = myArray.length - 1; counter >= 0; counter--) {
More Related Contents:
- What's the output of this code written in java?
- I keep getting java.lang.ArrayIndexOutOfBoundsException: 5! How do I fix this? [closed]
- How to add two int array values together?
- How to remove last comma and space in array? Java [duplicate]
- How to find size/length of an array without using library functions/variables [closed]
- how to replace display array list equals another array list values
- java programming homework 2015 [closed]
- How to compare variables in a loop, java
- Finding the max/min value in an array of primitives using Java
- Convert ArrayList to String[] array [duplicate]
- Can I pass an array as arguments to a method with variable arguments in Java?
- Convert an array of primitive longs into a List of Longs
- Generic array creation error
- Cannot create an array of LinkedLists in Java…?
- How to convert an int array to String with toString method in Java [duplicate]
- Variable length (Dynamic) Arrays in Java
- ArrayIndexOutOfBoundsException when iterating through all the elements of an array
- How to get unique values from array
- How does the Java array argument declaration syntax “…” work?
- Post increment operator not incrementing in for loop [duplicate]
- Converting string arrays into Map
- How does one instantiate an array of maps in Java?
- for loop in Java runs 3 times before taking next input
- get closest value to a number in array
- why is the enhanced for loop more efficient than the normal for loop
- Generate Random Numbers in Array [duplicate]
- How can I create an array in Kotlin like in Java by just providing a size?
- Getting the length of two-dimensional array
- String to char array Java
- Error of int cannot be dereferenced?