Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

输出一个等腰三角形 #111

Open
Sunny-117 opened this issue Nov 3, 2022 · 1 comment
Open

输出一个等腰三角形 #111

Sunny-117 opened this issue Nov 3, 2022 · 1 comment

Comments

@Sunny-117
Copy link
Owner

No description provided.

@kangkang123269
Copy link

kangkang123269 commented Sep 11, 2023

输出n = 3
输出:

    *
   ***
  *****
function printTriangle(n) {
    for(let i = 0; i < n; i++) {
        let str = '';
        // 添加左侧的空格
        for(let j = 0; j < n - i - 1; j++) {
            str += ' ';
        }
        // 添加星号
        for(let k = 0; k < 2 * i + 1; k++) {
            str += '*';
        }
        
        console.log(str);
    }
}

printTriangle(5);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants