문제 설명
이 문제에는 표준 입력으로 두 개의 정수 n과 m이 주어집니다.
별(*) 문자를 이용해 가로의 길이가 n, 세로의 길이가 m인 직사각형 형태를 출력해보세요.
제한 조건
-
n과 m은 각각 1000 이하인 자연수입니다.
예시
입력
5 3
출력
*****
*****
*****
소스코드 ( 1 for) 평균 속도 159ms
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int col = sc.nextInt();
int row = sc.nextInt();
for(int i=0; i< row; i++){
System.out.println(String.format("%"+col+"s"," ").replace(" ","*"));
}
}
}
소스코드 ( 2 for ) 평균 속도 162ms
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int col = sc.nextInt();
int row = sc.nextInt();
for(int i=0; i< row; i++){
for(int j=0; j<col; j++){
System.out.print("*");
}
System.out.println();
}
}
}
'Algorithm > Programmers' 카테고리의 다른 글
카카오 [1차] 비밀지도 (0) | 2020.01.30 |
---|---|
예산 (0) | 2020.01.24 |
행렬의 덧셈 (0) | 2020.01.24 |
x만큼 간격이 있는 n개의 숫자 (0) | 2020.01.21 |
핸드폰 번호 가리기 (0) | 2020.01.21 |