나의 풀이
import java.util.Scanner;
class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
for(int i=0; i<m; i++){
for(int j=0; j<n; 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()));
}
}
보충 학습
@Test
public void for_loop() {
for (int i = 1 ; i <= 10 ; i++) {
System.out.println(i);
}
}
위 코드를 IntStream으로 표현하면 다음과 같다. IntStream(start, end) 는 start부터 end직전까지를 의미한다.
@Test
public void intStream_range() {
IntStream.range(1, 11).forEach(System.out::println);
}
'프로그래머스(자바) > LV.1(자바)' 카테고리의 다른 글
이상한 문자 만들기★★★ (0) | 2022.12.16 |
---|---|
최대공약수와 최소공배수★★ (0) | 2022.12.15 |
문자열 다루기 기본→정규식 표현★★+match() (0) | 2022.12.15 |
내적 →map()의 역할★★ (0) | 2022.12.15 |
수박수박수박수박수박수?→ for문의 i와 삼항연산자+StringBuffer()+append() (0) | 2022.12.15 |