I am trying to print out this pattern using a for loop in java but I am kind of stuck.
zzzzz
azzzz
aazzz
aaazz
aaaaz
aaaaa
I can print:
a
aa
aaa
aaaa
aaaaa
using:
String i = " ";
int a = 0;
for (i="a";i.length()<=5;i=i+"a")
System.out.println(i);
and
zzzzz
zzzz
zzz
zz
z
using:
String i = " ";
for (i="zzzzz";i.length()>0;i=i.substring(0,i.length()-1))
System.out.println(i);
but i cant figure out how to combine them.i was thinking about replacing the substring of i and increasing the value of the end index by one everytime but not sure of to code it. i started with something like this:
String i = " ";
String b = " ";
for (i="zzzzz";i="aaaaa";i=i.replace(i.substring(0,))
System.out.println(i);
Any ideas?