What is the output of the following program int a new int5
What is the output of the following program?
 
 int[] a = new int[5];
 a[0] = 0;
 for (int i = 1; i <= 4; i++)
 {
   a[i] = a[i-1] + i;
   System.out.print(a[i] + \" \");
 }
Solution
Output of the mentioned snippet will be as below.
---------------------------------------------------------------------------------------------------------------------------------------------------------
Code:
int[] a = new int[5];
 a[0] = 0;
 for (int i = 1; i <= 4; i++)
 {
   a[i] = a[i-1] + i;
   System.out.print(a[i] + \" \");
 }
---------------------------------------------------------------------------------------------------------------------------------------------------------
Answer:
1 3 6 10 {i.e 1, 3, 6, 10}
![What is the output of the following program? int[] a = new int[5]; a[0] = 0; for (int i = 1; i <= 4; i++) { a[i] = a[i-1] + i; System.out.print(a[i] + \ What is the output of the following program? int[] a = new int[5]; a[0] = 0; for (int i = 1; i <= 4; i++) { a[i] = a[i-1] + i; System.out.print(a[i] + \](/WebImages/44/what-is-the-output-of-the-following-program-int-a-new-int5-1138028-1761609625-0.webp)
