Modify your program from the previous exercise so that it uses a global constant for the figure’s height. (You may want to make loop tables first.) The previous output used a constant height of 6. The following are the outputs for constant heights of 4 and 8:
Program:
public class Ch02Ex17
{
public static final int HEIGHT = 8;
public static void main(String[] args)
{
for (int r = 1; r <= HEIGHT; r++)
{
for (int c = 1; c <= 2 * r - 2; c++)
{
System.out.print("\\");
}
for (int c = 1; c <= 4 * HEIGHT - 4 * r + 2; c++)
{
System.out.print("!");
}
for (int c = 1; c <= 2 * r - 2; c++)
{
System.out.print("/");
}
System.out.println();
}
}
}
Output: