프로그래머스/[프로그래머스 - JAVA] Lv.1
[프로그래머스 - JAVA] 직사각형 별찍기
코딩하는 흰둥이
2023. 3. 29. 22:30

- 내 풀이
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();
// b가 세로의 길이기 때문에 먼저 돌아야한다
for (int i = 0; i < b; i++) {
// a가 가로의 길이기 때문에 세로가 한번 돌때 가로가 한줄 도는식
for (int j = 0; j < a; j++) {
System.out.print("*");
}
System.out.println();
}
// System.out.println(a + b);
}
}
- 다른 사람 풀이
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
String star = "";
for(int i=1; i<=a; i++){
star += "*";
}
for(int i=1; i<=b; i++){
System.out.println(star);
}
}
}