Find the errors in the given program segment and re-write the statements correctly to assign values to an integer array.

int a = new int (5);
for (int i=0; i<=5; i++) a[i]=i;

Views 9

Answer:

Corrected Code:


int a[] = new int[5];
for (int i = 0; i < 5; i++)
    a[i] = i;

Related Articles:

This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of Java Programming Language, click the links and dive deeper into this subject.

Join Our telegram group to ask Questions

Click below button to join our groups.