728x90
반응형
1. 입력받고 문자열 자를 경우
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
/*
1 2 3... 입력
*/
int n = Integer.parseInt(br.readLine()); // read, readLine 밖에 없으므로 정수는 파싱 필요
for (int i = 0; i < n; i++) {
String[] text = br.readLine().split(" "); // 1, 2, 3..
}
2. 숫자 입력받고 숫자만큼 문자열 입력
/*
n = 3
*/
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(bf.readLine()); // 3
/**
a
b
c 입력
*/
for (int i = 0; i < n; i++) {
String str = bf.readLine(); // 한줄에 한단어
}
반응형
'Coding Test 연습' 카테고리의 다른 글
[Baekjoon 16198번] 에너지 모으기 문제 (with 자바) (0) | 2021.10.10 |
---|---|
[프로그래머스] Level3 12936번: 줄 서는 방법 (JAVA) (0) | 2021.10.08 |
[Baekjoon 15658번] 연산자 끼워넣기(2) 문제 (with 자바) (0) | 2021.10.01 |
[Baekjoon 14888번] 연산자 끼워넣기 문제 (with 자바) (0) | 2021.10.01 |
[프로그래머스] Level3 12938번: 최고의 집합 (JAVA) (0) | 2021.09.30 |