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

    [JAVA 문제 풀이] 247. 직사각형 별찍기

    프로그래머스 (12969)
    Stupefyee's avatar
    Stupefyee
    May 12, 2025
    [JAVA 문제 풀이] 247. 직사각형 별찍기
    Contents
    내가 작성한 코드다른 사람의 코드
    school.programmers.co.kr
    https://school.programmers.co.kr/learn/courses/30/lessons/12969
    notion image
     

    내가 작성한 코드

    import java.util.Scanner; class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); for(int i = 0; i < b; i++) { for (int j = 0; j < a; j++) { System.out.print("*"); } System.out.println(); } } }
     

    다른 사람의 코드

    import java.util.Scanner; import java.util.stream.IntStream; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); StringBuilder sb = new StringBuilder(); IntStream.range(0, a).forEach(s -> sb.append("*")); // a만큼 한 줄 만들어 놓기 IntStream.range(0, b).forEach(s -> System.out.println(sb.toString())); // b만큼 반복 출력 } }
     
    Share article
    Contents
    내가 작성한 코드다른 사람의 코드

    stupefyee

    RSS·Powered by Inblog