Find and correct the errors in the following program segment and then
predict the output:
int n[ ] = (2, 4, 6, 8, 10);
for (int i=0; i<=5; i++)
System.out.println(“n[“ + i +"]=“ + n[i]);
Answers
Answered by
9
Answer:
Correct program:-
int n[]=[2,4,6,8,10];
for(int i=0;i<=4;i++)
System.out.println(i+“ ="+ n[i]);
OUTPUT:-
0=2
1=4
2=6
3=8
4=10
Answered by
26
It's wrong.
Check out my answer,
int n[] = {2,4,6,8,10};
for(int i=0;i<=5;i++)
System. out. println("n["+i+"]="+n[i]);
Output:-
n[0]=2
n[1]=4
n[2]=6
n[3]=8
n[4]=10
Similar questions