Tuesday, 15 April 2014

java - How to return print line values stored in an array using a for loop -



java - How to return print line values stored in an array using a for loop -

this question has reply here:

c++ - using 'i' check different variables in loop 3 answers

so can simple long way below

system.out.println(myarray[1]); //this = 1.56 system.out.println(myarray[2]); //this = 1.72

but how using loop retrieve values , print them?

for (int = myarray[]; j < myarray.length; i++) { system.out.println(i); }

so loop go through array , println values stored @ positions e.g [1] = 1.56, [2] = 1.72. how loop this? thanks

just print myarray[i] in loop:

for (int = 0; < myarray.length; ++i) { system.out.println(myarray[i]); }

i had prepare loop variable.

another way utilize "for each" loop:

for (double val : myarray) { system.out.println(val); }

java arrays for-loop

No comments:

Post a Comment