- import java.util.Scanner;
- public class Example18 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.print("请输入一个数字:");
- int s = sc.nextInt();
- tianZi(s);
- }//可以改成田字。
- public static void tianZi(int x) {
- for (int i = 1;i<x;i++) {
- if (i==x/2) {
- System.out.print("");
- }else {
- for (int y = 1;y<=i;y++) {
- System.out.print("* ");
- if(y==x/2) {
- System.out.print(" ");
-
- }
- }
- }
- System.out.println();
- }
-
- }
- }
复制代码 |