프로그래머스 C# 직각삼각형 출력하기(파이썬, 자바)

2023. 4. 15. 14:38C# 알고리즘 코딩(프로그래머스)

using System;

public class Example
{
    public static void Main()
    {
        String[] s;

        Console.Clear();
        s = Console.ReadLine().Split(' ');

        int n = Int32.Parse(s[0]);

        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= i; j++)
            {
                Console.Write("*");
            }
            Console.WriteLine();
        }
    }
}

 

 

파이썬

 

 

n = int(input())
for i in range(n):
    print('*'*(i+1))

 

//////

 

n = int(input())
for i in range(1,n+1):
    print('*'*i)

 

 

자바

 

 

import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        for(int i=1; i<=n; i++)
        {
            System.out.println("*".repeat(i));
        }
    }
}

 

 

import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        for(int i=0; i<n; i++)
        {
            for(int j=0; j<=i; j++)
            {
                System.out.print("*");
            }
            
            System.out.println();
        }

    }
}