This method returns a string with a rectangle that has maxRows and maxCols, using the symbol character. The method will return a special value null if maxRows and maxCols are less than 1. The method most not rely on System.out.println(). No Arrays
public class DrawingApp {
public static String getRectangle(int maxRows, int maxCols, char symbol){
if(maxRows<1 || maxCols<1){
return null;
}
else {
String result = "";
for (int i = 0; i < maxRows; i++) {
for (int j = 0; j < maxCols; j++) {
result = result + symbol;
}
result = result + "\n";
}
return result;
}
}
public static void main(String[] args) {
System.out.print(DrawingApp.getRectangle(4, 11,'A'));
System.out.print(DrawingApp.getRectangle(4, 11,'B'));
System.out.print(DrawingApp.getRectangle(4, 11,'C'));
}
}
OUTPUT:
AAAAAAAAAAA AAAAAAAAAAA AAAAAAAAAAA AAAAAAAAAAA BBBBBBBBBBB BBBBBBBBBBB BBBBBBBBBBB BBBBBBBBBBB CCCCCCCCCCC CCCCCCCCCCC CCCCCCCCCCC CCCCCCCCCCC
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images