2021-04-26输出三角形

输出三角形

1, 打印如图类似的三角形

 

2,继续打印 打印出一个菱形(再来一个倒置三角) 本质找规律题 不喜

package com.cnm.cn;

import java.util.Scanner;

public class Add1 {
    public static void main(String[] args) {
        int lines;
        while (true){
        Scanner sc = new Scanner(System.in);
        System.out.println("输入要几行");
        lines = sc.nextInt();
        if (lines%2!=0){break;}}
        for (int line = 1; line <= lines; line++) {
            for (int row = 1; row <= lines - line; row++) {
                System.out.print(" ");
            }
            for (int rows = 1; rows <= 2 * line - 1; rows++) {
                System.out.print("*");
            }
            System.out.println();
        }
        int lf=lines/2;
        int lt=lf+1;
        for (int lingline = 1; lingline <=lt; lingline++) {
            for (int rowss=1;rowss<=lt-lingline;rowss++){
                System.out.print(" ");
            }
            for(int rowst=1;rowst<=2*lingline-1;rowst++){
                System.out.print("*");
            }
            System.out.println();
        }

        for(int rows1=1;rows1<=lf;rows1++){
            for (int xingf1=1;xingf1<=rows1;xingf1++){
                System.out.print(" ");
            }
            for (int xingf=1;xingf<=(lines-2*rows1);xingf++){
                System.out.print("*");
            }
            System.out.println();
        }
        for(int rows1=1;rows1<=lines;rows1++){
            for (int xingf1=1;xingf1<=rows1-1;xingf1++){
                System.out.print(" ");
            }
            for (int xingf=1;xingf<=(2*lines-1)-2*(rows1-1);xingf++){
                System.out.print("*");
            }
            System.out.println();}

    }
}


//   *          3   1          n/2+1-l   2l-1          1   13   13-2*n-1     2n-1-pow(2,n-1)                            0   7   2n-1  0
//  ***          2   3         n/2+1-l   2l-1          2   11    13-2*n-1                                               1  5        1
// *****         1    5                               3    9     13-2*n-1                                               2  3
//*******        0    7                                4   7       13-2*n-1   4 7                                      3   2
// *****        1    5       n/2 3 1   l-n/2-1          5 5   3              5   5   1  5   line-2*n-1   5 1   1    2n-1
//  ***          2    3          3  2  6   6-3-1       6  3   3               6   3  2  3              6  3    2
//   *           3    1         3   3   7             7    1    3                    3  1               7   5   3
//
//***********     1   9 2n-1   0
// *********      2           1
//  *******      3            2
//   *****       4           3
//    ***
//     *   5              4

//*******  1 0
// *****   2 1
//  ***    3 2
//   *

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值