공부하기/백준

[Java] 백준 풀기 15232 - Rectangles

XEV 2023. 3. 31. 23:48

자바 백준 15232번

브론즈 4

https://www.acmicpc.net/problem/15232

 

15232번: Rectangles

Read two integer numbers R and C from the standard input and then print R lines with C asterisks (*) each. Example (R=3, C=5): ***** ***** ***** Example (R=2, C=10): ********** **********

www.acmicpc.net

 

 

 

 

 

문제 보기

분류: 구현

 

 

 

 

 

문제 풀기

row 와 column 으로 주어지는 두 개의 숫자만큼 "*" 를 사각형 모양으로 출력한다.

row 의 경우 for loop 을 이용하여 반복 출력하고, column 의 경우에는 repeat() 함수를 이용하여 asterisk 를 반복 출력한다.

 

 

 

 

 

코드 보기

import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int r = sc.nextInt();
int c = sc.nextInt();
for (int i = 0; i < r; i++) {
String unit_asterisk = "*";
String asterisks = unit_asterisk.repeat(c);
System.out.println(asterisks);
}
}
}