用双重for循环打出来的图形
import java.util.Scanner;
public class Test02 {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.println("请输入要打印的行数");
int rows=input.nextInt();
System.out.println("矩形");
for (int i = 1; i <=rows; i++) {
for (int j = 1; j <= rows; j++) {
System.out.print("*");
}
System.out.println();
}
System.out.println("直角三角型");
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= i; j++) {
System.out.print("*");
}
System.out.println();
}
System.out.println("等腰三角型");
for (int i = 1; i <= rows; i++) {
for (int j =rows-i-1; j >=0; j--) {
System.out.print(" ");
}
for (int j = 1; j <= 2*i-1; j++) {
System.out.print("*");
}
System.out.println();
}
System.out.println("菱形");
for (int i = 1; i <= rows; i++) {
for (int j =rows-i-1; j >=0; j--) {
System.out.print(" ");
}
for (int j = 1; j <= 2*i-1; j++) {
System.out.print("*");
}
System.out.println();
}
for (int i = 1; i <= rows-1; i++) {
for (int j = 1; j <=i; j++) {
System.out.print(" ");
}
for(int j=1;j<=2*(rows-i)-1;j++){
System.out.print("*");
}
System.out.println();
}
}
}
程序运行图
请输入要打印的行数
5
矩形
*****
*****
*****
*****
*****
直角三角型
*
**
***
****
*****
等腰三角型
*
***
*****
*******
*********
菱形
*
***
*****
*******
*********
*******
*****
***
*