打印倒金字塔

``` java
package test ;
import java . util . Scanner ;
class file {
public static void main ( String []args ){
Scanner scan =new Scanner (System .in );
System .out . println ( " 请输入行数: " );
int n =scan . nextInt ();
for ( int hang = 1 ; hang <= n ; hang ++ ){
for ( int space = 1 ; space <= hang - 1 ; space ++ ){
//第hang行输出hang-1个空格
System .out . print ( " " );
}
for ( int star = 1 ; star <= 2 * n - 2 * hang + 1 ; star ++ ){
//第hang 行输出2*n-1 + (-2)*(hang-1)
//2*n-1 2*n-3 ...3 ,1|1,2,3...n
System .out . print ( " * " );
}
System .out . println ();
}
}

}

```

你可能感兴趣的:(learn,java)