Write a method called printDesign that produces the following output. Use nested for loops to capture the structure of the figure.
-----1-----
----333----
---55555---
--7777777--
-999999999-
Program:
public class Ch02Ex15
{
public static void main(String[] args)
{
printDesign();
}
public static void printDesign()
{
int n = 1;
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= 6 - i; j++)
{
System.out.print("-");
}
for (int j = 1; j <= n; j++)
{
System.out.print(n);
}
for (int j = 1; j <= 6 - i; j++)
{
System.out.print("-");
}
System.out.println();
n += 2;
}
}
}
Output:
-----1-----
----333----
---55555---
--7777777--
-999999999-