when i trace the code
You debug it. While debugging you figure several operations in one line:
for (int i =1; i<=4; i++)
{
a[i]=a[i-1]+i;
System.out.print(a[i]+" ");
}
should be
for (int i =1; i<=4; i++)
{
int iNumber = a[i-1];
iNumber += i;
a[i]=iNumber;
System.out.print(a[i]+" ");
}
This way you can figure every step and see that the output if this is "1 3 6 10".