# Arrays

Shah Chunky
Ranch Hand
Posts: 116
Why does Loop at line 2 prints all 0's even if i have assigned the array 'a' at line 1.

class ArrArgs
{
public static void main(String[] args)
{
ArrArgs aa = new ArrArgs(10);
int w[] = aa.reverse(aa.arr);
}

private int[] arr;
ArrArgs(int size) // Constructor
{
arr = new int[size];
}

public int[] reverse(int[] arr)
{
int[] a = new int[10];
for(int i = 0; i < arr.length; i++) <br /> {<br /> arr[i] = i;<br /> }<br /> <br /> for(int i = arr.length-1; i >= 0 ; i--)
{
for (int j=0;j<10;j++)<br /> {<br /> a[j] = arr[i]; // Line 1<br /> }<br /> System.out.println("a[" + i + "]" + "= " + a[i]);<br /> } <br /> System.out.println();<br /> <br /> for(int j = a.length-1; j >= 0 ; j--) // Line 2
{
System.out.println("a[" + j + "]" + a[j]);
}
return arr;
}
}

nan s
Greenhorn
Posts: 16
That's right,
i mean:
first; program set arr[0] = 0
then; program set a[j] = 10
then set a[j] =9
then set a[j] =8
....
at last set a[j] = 0
that's why print all '0'

 Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters?