나의 풀이
import java.util.Scanner;
import java.util.stream.IntStream;
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("*"));
IntStream.range(0, b).forEach(s -> System.out.println(sb.toString()));
}
}
StringBuilder 관련 글
자바 stream 관련 글
- for-loop 를 Stream.forEach() 로 바꾸지 말아야 할 3가지 이유
원시 데이터(primitive data type)를 반복문으로 처리할 때는 절대적으로 전통적인 for-loop를 써야한다.(collections보다 배열의 경우에는 특히 더)- Stream의 foreach 와 for-loop 는 다르다.
- Collection.forEach와 Stream.forEach는 뭐가 다를까?