Hi
check out the following code
Q. What code placed after the comment //For loop would populate the elements of the array ia[] with values of the variable i.?
public class Lin{
public static void main(
String argv[]){
Lin l = new Lin();
l.amethod();
}
public void amethod(){
int ia[] = new int[4];
//Start For loop
{
ia[i]=i;
System.out.println(ia[i]);
}
}
}
1) for(int i=0; i < ia.length(); i++)
2) for (int i=0; i< ia.length(); i++)
3) for(int i=1; i < 4; i++)
4) for(int i=0; i< ia.length;i++)
Answer given is 4.
it's correct but I think 3 is also correct, because in case of 3 the array will be like this
[0,1,2,3]
here also the values papulated are same as the vale of i.
Does anybody wants to put comment?