- /*
- *打印等腰梯形
- */
- import java.util.*;
- public class ti_5_2{
- public static void main(String[] args)
- {
- //第0行9个 空个数目 第3行 有0个
- //第1行 11个 第2行 有1个
- //第2行 13个 第1行 有2个
- //第3行 15个 第0行 有3个
- //第n行 9+i*2个 n n-1个
- System.out.println("请输入要打印的行数:");
- Scanner sc=new Scanner(System.in);
- int n=sc.nextInt();
- System.out.println("打印"+n+"行");
- int i,j;
- for(i=0;i<n;i++)
- { int k=i;
- while(k<n)
- {
- System.out.print(" ");
- k++;
- }
- for(j=1;j<=9+i*2;j++)
- {
- System.out.print("*");
- }
- System.out.println();
- }
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/251020136682.html
来源: http://www.codesnippet.cn/detail/251020136682.html