
내가 작성한 코드
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