Пытается написать программу, которая напечатает несколько шаблонов треугольников, как полых, так и твердых. Я реализовал это, используя конструкторы, а также другие утилиты. На данный момент я пытаюсь отобразить треугольник размером 7 со следующим символом (*).Печать шаблона Java Triangle
по какой-то причине я только получаю следующий результат: 0000. Я создал тестовый треугольник вниз
Triangle s1 = new Triangle(7, '*');
s1.displaySolidUL();
public class Triangle {
// Declare & intialize data fields
final private static char defaultChar = '*';
final private static int defaultSize = 10;
private static char triangleChar;
private static int triangleSize;
private static int triangleCount = 0;
// Constructors
public Triangle() {
this(defaultSize, defaultChar);
}
public Triangle(int s) {
this(s, defaultChar);
}
public Triangle(char n) {
this(n, defaultChar);
}
public Triangle(int size, char character) {
if ((triangleSize <= 0) || (triangleSize > 50)) {
size = defaultSize;
// System.out.println(errorSizeMsg);
} else if (triangleChar == ' ') {
character = defaultChar;
// System.out.println(errorBlankChar);
} else {
size = triangleSize;
character = triangleChar;
// increment triangle count
triangleCount++;
}
}
// Accessors and Mutators
public int getSize() {
return triangleSize;
}
public char getChar() {
return triangleChar;
}
public void setSize(int size) {
triangleSize = size;
}
public void setChar(char character) {
triangleChar = character;
}
// Main methods for displaying triangles
public void displaySolidLL() {
}
public void displaySolidLR() {
}
public void displaySolidUL() {
for (int row = 0; row <= triangleSize; row++) {
for (int col = 0; col <= row; col++) {
System.out.print(triangleChar);
}
System.out.println();
}
}
public void displaySolidUR() {
}
// Other utility classes
// Printing out new lines
public static void newLine(int numLines) {
for (int i = 0; i < numLines; i++) {
System.out.println();
}
}
// Display triangle count
public static void getTriangleCount() {
System.out.print("The total number of triangles printed equals: " + triangleCount);
}
}
Пересмотренный мой цикл к вашему пересмотренному дизайну .. все еще, кажется, не сотрудничает – Chewy