일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- SECS-II
- 파이썬
- Spring JPA
- c
- java
- 비트코인
- Computer Science
- 백준
- Gem
- Digital Marketing
- C++
- SECS/GEM
- Investing
- 프로그래머스
- Baekjoon
- SECS
- modern c++
- finance & economics
- 자바
- Spring
- 회원가입
- CS
- coins
- Cars
- 지브리필터
- programmers
- python
- 암호화폐투자
- spring boot
- ai이미지변환
Archives
- Today
- Total
비버놀로지
[Programmers 프로그래머스] 12969 직사각형 별찍기 본문
반응형
programmers.co.kr/learn/courses/30/lessons/12969
코딩테스트 연습 - 직사각형 별찍기
이 문제에는 표준 입력으로 두 개의 정수 n과 m이 주어집니다. 별(*) 문자를 이용해 가로의 길이가 n, 세로의 길이가 m인 직사각형 형태를 출력해보세요. 제한 조건 n과 m은 각각 1000 이하인 자연수
programmers.co.kr
입력값을 이용해서 배열을 만들어 주고, arrays.fill을 이용해서 *을 넣어준다.
그렇게 만들어진 배열을 System.out을 이용해서 화면에 출력을 해준다.
import java.util.Scanner;
import java.util.Arrays;
public class Solution {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
char arr[][]=new char[b][a];
for (int i = 0; i < arr.length; i++) {
Arrays.fill(arr[i], '*');
}
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[0].length; j++) {
System.out.print(arr[i][j]);
}
System.out.println();
}
}
}
반응형
'ALGORITM > JAVA' 카테고리의 다른 글
[Programmers 프로그래머스] 17681 [1차] 비밀지도 (0) | 2021.01.10 |
---|---|
[Programmers 프로그래머스] 12982 예산 (0) | 2021.01.08 |
[Programmers 프로그래머스] 12954 x만큼 간격이 있는 n개의 숫자 (0) | 2021.01.08 |
[Programmers 프로그래머스] 12950 행렬의 덧셈 (0) | 2021.01.08 |
[Programmers 프로그래머스] 12948 핸드폰 번호 가리기 (0) | 2021.01.08 |
Comments