2775번 - 부녀회장이 될테야
제가 머리가 안좋아서 이방법밖에 생각이 안나는데 혹시 왜 런타임 에러 나는지 알려주실수 있습니까 ?
결과는 잘나옵니다.
----------------------------------------------------------------------------------
import java.io.IOException;import java.util.Scanner;
public class Main { public static void main(String[] args) throws IOException { int sum = 0; int [][] table = new int[14][14]; for(int i = 0; i<table.length; i++) { for(int j=0; j<table[0].length;j++) { if(i==0) { table[i][j] = j+1; } else { sum = 0; for(int k=0; k<=j; k++) { sum = sum + table[i-1][k]; } table[i][j] = sum; } } } Scanner sc = new Scanner(System.in); int testcase_number = sc.nextInt(); int floor = 0; int room_number = 0; for(int i=0;i<testcase_number;i++) { floor = sc.nextInt(); room_number = sc.nextInt(); System.out.println(table[floor][room_number-1]); } //try_arry(table); } public static void try_arry(int[][] table) { for(int i = 0 ; i<table.length;i++) { for(int j = 0; j<table[0].length;j++) { System.out.printf("%9d"+" ",table[i][j]); } System.out.println(); } }}
1
14
에서 에러가 납니다.
감사합니다. 잘해결했습니다.
댓글을 작성하려면 로그인해야 합니다.
sh3233 6년 전
제가 머리가 안좋아서 이방법밖에 생각이 안나는데 혹시 왜 런타임 에러 나는지 알려주실수 있습니까 ?
결과는 잘나옵니다.
----------------------------------------------------------------------------------
import java.io.IOException;
import java.util.Scanner;
public class Main
{
public static void main(String[] args) throws IOException
{
int sum = 0;
int [][] table = new int[14][14];
for(int i = 0; i<table.length; i++)
{
for(int j=0; j<table[0].length;j++)
{
if(i==0)
{
table[i][j] = j+1;
}
else
{
sum = 0;
for(int k=0; k<=j; k++) { sum = sum + table[i-1][k]; }
table[i][j] = sum;
}
}
}
Scanner sc = new Scanner(System.in);
int testcase_number = sc.nextInt();
int floor = 0;
int room_number = 0;
for(int i=0;i<testcase_number;i++)
{
floor = sc.nextInt();
room_number = sc.nextInt();
System.out.println(table[floor][room_number-1]);
}
//try_arry(table);
}
public static void try_arry(int[][] table)
{
for(int i = 0 ; i<table.length;i++)
{
for(int j = 0; j<table[0].length;j++)
{
System.out.printf("%9d"+" ",table[i][j]);
}
System.out.println();
}
}
}