첫 코딩테스트 연습
[내가 푼 방식]
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()));
'Algorithm 알고리즘' 카테고리의 다른 글
[프로그래머스 Lv1]평균구하기(JAVA) (0) | 2021.08.27 |
---|---|
[프로그래머스 Lv1]하샤드 수(JAVA) (0) | 2021.08.27 |
[프로그래머스 Lv1]핸드폰 번호 가리기(JAVA) (0) | 2021.08.26 |
[프로그래머스 Lv1]행렬의 덧셈(JAVA) (0) | 2021.08.25 |
[프로그래머스 Lv1]x만큼 간격이 있는 n개의 숫자(JAVA) (0) | 2021.08.24 |