Algorithm 알고리즘
[프로그래머스 Lv1]직사각형 별찍기(JAVA)
jy-agnes-lee
2021. 8. 23. 14:00
첫 코딩테스트 연습
[내가 푼 방식]
1. for문을 두 개 활용한다.
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 c = 0; c < b; c++){
for(int d = 0;d < a;d++){
System.out.printf("*");
}
System.out.println();
}
}
}
[참고해보고 싶은 방식과 그 이유]
StringBuilder sb = new StringBuilder();
IntStream.range(0, a).forEach(s -> sb.append("*"));
IntStream.range(0, b).forEach(s -> System.out.println(sb.toString()));