- Scanner sc = new Scanner(System.in);
- int n = 6;
- while (n !=0)
- {
- System.out.print("n = ");
- n = sc.nextInt();
- int m = 2*n-1;
- for (int x = 1;x <=n ;x++ )
- {
- for (int y =x+1;y <=n ;y++ )
- {
- System.out.print(" ");
- }
- for (int z =1;z <=x ;z++ )
- {
- System.out.print("* ");
- }
- System.out.println();
- }
- for (int a = (n+1);a <=m ;a++ )
- {
- for (int b =n+1;b <=a ;b++ )
- {
- System.out.print(" ");
- }
- for (int c =a;c <=m ;c++ )
- {
- System.out.print("* ");
- }
- System.out.println();
- }
复制代码 |
|