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] + \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site