- import java.util.Scanner;
- class Test3_ForForStar {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.println("请输入边长");
- int l = sc.nextInt();
- print(l);
- public static void print(int l) {
-
- for (int x = 1 ; x <= l ; x++ ) {
- for (int y = x ; y < l ; y++ ) {
- System.out.print(" ");
- }
- for (int z = 1 ; z <= x ; z++ ) {
- if ((x > 2 && x < l) && (z > 1 && z < x)) {
- System.out.print(" ");
- }else {
- System.out.print("* ");
- }
-
- }
- System.out.println();
- }
- }
- }
复制代码
|
|