Skip to content

Instantly share code, notes, and snippets.

@connlark
Created October 30, 2015 05:37
Show Gist options
  • Save connlark/36368fb1f8fd5ad191ea to your computer and use it in GitHub Desktop.
Save connlark/36368fb1f8fd5ad191ea to your computer and use it in GitHub Desktop.
/**
* Created by Connor on 10/30/15.
*/
public class Ch6Hw8 {
public static void printV(int height) {
int width = (height * 2) - 1;
int farV = width;
for (int i = 1; i <= height; i++, farV--) {
for (int j = 1; j <= width; j++) {
if (i - j == 0 || farV == j) {
System.out.print("X");
} else {
System.out.print(" ");
}
}
System.out.println();
}
}
public static void drawPyramid(int height) {
String spaces = "";
for (int i = 0; i < height; i++) {
System.out.print(spaces + "*" + spaces);
if (i != 0) System.out.print("*");
System.out.println();
spaces += " ";
}
}
public static void printX(int height) {
int farX = height;
for (int i = 1; i <= height; i++) {
for (int j = 1; j <= height; j++) {
if (i == j || farX == j) {
System.out.print("X");
} else {
System.out.print(" ");
}
}
System.out.println();
farX--;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment