Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Displaying an Array using for loops

I have an array with some set numbers and am looking to display the index and value of each using a for loop.

Here is the array:

int[] myArray = {8,4,5,21,7,9,18,2,100};

And here is my loop so far, just don’t know what to put inside:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

for(int i = 0; i < myArray.length; i++)

>Solution :

You can access the value of index i using myArray[i] in the loop

for(int i = 0; i < myArray.length; i++) {
    System.out.println("index = " + i + ", value = " + myArray[i]);
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading