✏️ 문제풀이/백준
[백준/Java] 10798번 :: 세로읽기
bono-hye
2024. 4. 23. 20:19
🌱 풀이
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
char arr[][] = new char[5][15];
for(int i=0; i < 5; i++)
{
String str = sc.nextLine();
for(int j=0; j < str.length(); j++)
arr[i][j] = str.charAt(j);
}
for(int i=0; i<15; i++)
{
for(int j=0; j<5; j++)
{
if(arr[j][i] != 0)
System.out.print(arr[j][i]);
}
}
sc.close();
}
}
💡 정리
세로로 출력하는 것이기 때문에 arr[i][j]가 아닌 arr[j][i]로 출력 반복문 수행
char 에서 != 0으로 null인지 확인 후 null이 아닐 때만 출력하는 것으로 조건문 설정