Write a code fragment that prints a length by height
rectangle of *'s. Assume that out is an appropriately
declared created OutputBox object.
for (int row = 0; row < height; row++) {
for (int col = 0; col < length - 1; col++)
out.print("*");
out.printLine("*");
}
Write a code fragment that prints a length by length
right triangle of *'s. Assume that out is an appropriately
declared created OutputBox object.
for (int row = 0; row < length; row++) {
for (int col = 0; col < row; col++)
out.print("*");
out.printLine("*");
}
Write a code fragment that prints a diamond of *'s that is n
wide at its widest.
// print the upper pyramid
for (int row = 1; row <= n; row++) {
for (int numSpaces = 0; numSpaces < n - row; numSpaces++)
System.out.print(" ");
for (int numStars = 0; numStars < row; numStars++)
System.out.print("* ");
System.out.println();
}
// print the lower pyramid
for (int row = n - 1; row > 0; row--) {
for (int numSpaces = 0; numSpaces < n - row; numSpaces++)
System.out.print(" ");
for (int numStars = 0; numStars < row; numStars++)
System.out.print("* ");
System.out.println();
}