inblog logo
|
silver
    알고리즘문제풀기

    [알고리즘문제풀기] 직각삼각형 출력하기

    silver's avatar
    silver
    Dec 15, 2024
    [알고리즘문제풀기] 직각삼각형 출력하기
    Contents
    문제내가 작성한 정답다른 사람들이 작성한 정답

    문제

    school.programmers.co.kr
    https://school.programmers.co.kr/learn/courses/30/lessons/120823

    내가 작성한 정답

    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++){ for(int k=1; k<=i; k++){ System.out.print("*"); } System.out.println(); } } }

    다른 사람들이 작성한 정답

    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)); } }
    💡
    System.out.println("*".repeat(i)); - i만큼 *를 반복해라.
     
    Share article

    silver

    RSS·Powered by Inblog