- import java.util.Scanner;
- public class LingXin {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner sc = new Scanner(System.in);
- System.out.println("请输入三角形的高:");
- int n = sc.nextInt();
-
- //打印上三角
- for (int i = 0; i < n - 1; i++) {
- for (int x = i + 1; x < n; x++) {
- System.out.print(" ");
- }
- for (int y = 0; y < (i + 1) * 2 - 1; y++) {
- System.out.print("*");
- }
- System.out.println();
- }
- //打印下三角
- for (int i = 0; i < n; i++) {
- for (int x = 0; x < i; x++) {
- System.out.print(" ");
- }
- for (int y = i; y < 2 * n - i - 1; y++) {
- System.out.print("*");
- }
- System.out.println();
- }
- }
- }
复制代码
运行结果:
输入5
请输入三角形的高:
5
*
***
*****
*******
*********
*******
*****
***
*
技术分怎么得啊?? |