输出连续字符窜

Beginning CS student here, trying to get a handle on loops. My task is to take a String s, such that if s = 'abcd', the program will print: 'a,b,c,d,ab,bc,cd,abc,bcd,abcd'. Clearly the begin index and end index change as the loop iterates—(0,1),(1,2),(2,3),(3,4). That's fine and I can print: 'a,b,c,d'. But how do I control it such that it will go from that to (0,2),(1,3),(2,4) and then (0,3),(1,4), and finally (0,4)? This is where I am stumped. Thanks for the assistance and here's my code: 
for (int i=0;i<len;i++)
{
    for (int k=0;k<len-i;k++)
       System.out.print(s.substring(k,k+i+1)+","); 
}




你可能感兴趣的:(输出连续字符窜)