I have following two arrays
int a[]={1,2,3,4,5,6,7,8,9};
int b[]={4,2,3}
Output should be
b[0] has 4 so the first line of output should be 1,2,3,4 (from array a )
b[1] has 2 so the 2nd line of output should be 5,6 (from array a )
b[2] has 3 so the 3rd line of outout should be 7,8,9 (from array a )
the output should be like this
1,2,3,4
5,6
7,8,9
I am trying with this code but it's not working
for(i=0;i<b[j];i++)
{
if(flag==false){
System.out.print(a[i]);
flag=true;
}
else
System.out.print(" "+a[i]);
}
j=j+1;
System.out.print("\n");
Note : there can be any number of elements in array a and b
jloop construct as well. (P.S: Check my answer, it seems to solve your question.)