I'm trying to put out the following pattern of chars:
x
xxx
xxxxx
xxxxxxx
xxxxxxxxx
And this is what I currently have:
String y = "";
for(int i = 0; i < 10; i++)
{
y="";
for(int s = 0; s < i; s++)
{
y+= "x";
}
System.out.println(y);
}
This outputs
x
xx
xxx
xxxx
xxxxx
xxxxxx
xxxxxxx
xxxxxxxx
Which is an approach. I'm well aware of the fact that the target pattern increments two x
each execution of the loop, and I know that I have to use blank spaces and insert them. However, I'm stuck with this really simple task.
EDIT: The task is to only use two loops. I thought of a way using three, though, but couldn't straight forwardly figure out a way to use two loops.