public static void main(String[] args) {
int height,width1,width2,width3;
height = 7;
width1 = 5;
width2 = 4;
width3 = 6;
test014_打印正方形和矩形 t= new test014_打印正方形和矩形();
//正方形
t.printZF(width1,width1);
t.printZF(width2,width2);
t.printZF(width3,width3);
System.out.println("---------------");
//長方形
t.printZF(height,width1);
t.printZF(height,width2);
t.printZF(height,width3);
}
public void printZF(int height, int width){
String str = "";
for (int i = 0;i<width;i++){
for (int j = 0;j<height;j++){
str+="* ";
}
str += "\n";
}
System.out.println(str);
}