- package com.sf;
- import java.util.*;
- public class test7 {
- public static void main(String[] args) {
-
- System.out.println("请输入一个正棱形的边");
-
- Scanner sc = new Scanner(System.in);
- int length = sc.nextInt();
- prismatic(length);
- sc.close();
-
- }
- private static void prismatic(int length){
-
- printKong(1);
- System.out.println("*");
- for(int x=2; x<=length; x++){
- printKong(x);
- System.out.print("*");
- //把三角形内部的星号去掉,三角形的底边是腰的二倍减去一,每一个内部小三角形的底边减去底边两端的星号即得空白符号的个数
- for(int z=0;z<2*x-3;z++){
-
- System.out.print(" ");
- }
-
- System.out.print("*");
- System.out.println();
- }
- for(int x=length-1; x>1; x--){
- printKong(x);
- System.out.print("*");
- //把三角形内部的星号去掉,三角形的底边是腰的二倍减去一,每一个内部小三角形的底边减去底边两端的星号即得空白符号的个数
- for(int z=0;z<2*x-3;z++){
-
- System.out.print(" ");
- }
-
- System.out.print("*");
- System.out.println();
- }
- printKong(1);
- System.out.println("*");
-
-
-
- }
- private static void printKong(int x){
- for(int y=0; y<16-x;y++){
-
- System.out.print(" ");
- }
-
- }
- }
复制代码 |
|