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

silver's avatar
Dec 15, 2024
[알고리즘문제풀기] 직각삼각형 출력하기

문제

내가 작성한 정답

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