Friday 15 February 2013

java - How exactly do arrays and for loops work together? -



java - How exactly do arrays and for loops work together? -

i understand arrays used store values when used loops loose track of happening. know output 100 because ran in terminal need understand how did 100 using loops , arrays because i'm not sure if uses 3 values or first one. in advance

here problem:

public class arrays { public static void main (string[] args) { int[] a1 = {1, 1, 3}; mystery(a1); } public static void mystery(int[] a) { (int = 1; < a.length - 1; i++) { a[i] = (a[i - 1] + a[i + 1]) /2; } } }

not exclusively sure question you're trying inquire - seek , help - help each time a[i] called, takes value of (also iteration number) @ each instance , uses find relevant array index - used rest of computation.

java arrays loops for-loop

No comments:

Post a Comment