String [] jjj={"venkat","venkat","venkat"};
String [] kkk={"such","such","such","such","such"};
for(int i=0; i<jjj.length;i++)
{
for(int j=0;j<i;j++)
{
System.out.println("first"+jjj[i]);
System.out.println("second"+kkk[j]);
}
Based on your code, there is nothing wrong with the output.
i j j<i output
----- ---- ----------- -----------
i = 0, j = 0 false -
i = 1, j = 0 true firstvenkat
i = 1, j = 1 false -
i = 2, j = 0 true firstvenkat
j = 1 true firstvenkat
j = 2 false -
i = 3
That's how it prints 3 times first "venkat" and 3 times second "such"
Not sure if this is what you want....
public class Loop {
/**
* @param args
*/
public static void main(String[] args)
{
String [] jjj={"venkat","venkat","venkat"};
String [] kkk={"such","such","such","such","such"};
for(int j = 0; j < jjj.length; j++)
{
if(j == 0)
{
System.out.println("jjj = " + jjj[j]);
}
for(int k = 0; k<kkk.length;k++)
{
if(k<jjj.length)
{
System.out.println("jjj = " + jjj[k]);
}
System.out.println("kkk = " + kkk[k]);
}
}
}
}