공백없이 2차원배열 데이터 String으로 한번에 한줄씩 입력받기(문자/숫자)
공백없이 2차원배열 char 데이터 한번에 한줄씩 입력받기 ①②
Scanner sc = new Scanner(System.in);
r = sc.nextInt();//행
c = sc.nextInt();//열
a = new char[r][c];
d = new int[r][c];
sc.nextLine();
for(int i=0;i<r;i++) {
String s = sc.nextLine();
for(int j=0;j<c;j++) {
a[i][j] = s.charAt(j);
}
}
주의할 점 sc.nextInt() 이후에 바로 nextLine()을 쓸경우 nextLine()을 한번 더 해주어야한다!
공백없이 2차원배열 int 데이터 한번에 한줄씩 입력받기
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] input = br.readLine().split(" ");
N = Integer.parseInt(input[0]);
M = Integer.parseInt(input[1]);
map = new int[N+1][M+1];
visited = new boolean[N+1][M+1][2];
for (int i = 1; i <= N; i++) {
input = br.readLine().split("");
for (int j = 1; j <= M; j++) {
map[i][j] = Integer.parseInt(input[j-1]);
}
}
bfs(1, 1);
}
공백없이 2차원배열 char 데이터 한번에 한줄씩 입력받기 ②
for(int i=0;i<n;i++){//n:행 갯수
map[i] = br.readLine().toCharArray();
}
Last updated
Was this helpful?