I am very new to coding and was just introduced to static methods, so I apologize in advance for the silly mistakes. The method should display a triangle when the method is called under main, but I am getting an empty console and there is no output. However, if I write this under main:
String triangle = getTriangle(3, 4);
System.out.println(triangle);
then, the triangle will be displayed in the console, but for this assignment, the string/triangle must be called by only using
getTriangle(maxRows, maxCols)
public class Triangle {
public static String getTriangle(int maxRows, int maxCols) {
String T = "";
if (maxRows < 1 || maxCols < 1) {
return null;
} else {
for (int row = 1; row <= maxRows; row++) {
for (int col = 1; col <= row; col++) {
T += "*";
}
T += "\n"; }
}
return T;
}
}
public static void main(String[] args) {
getTriangle(3,2);
}
}