import java.io.*;
public class Exam_01{
public static void main(String[] ar) throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int inwon = 0;
String[] name = null;
int[] age = null;
System.out.print(\"인원 = \");
inwon = Integer.parseInt(in.readLine());
name = new String[inwon];
age = new int[inwon];
for(int i = 0; i < inwon; i++){
System.out.print(i+1 + \"번째 사람 이름 = \");
name[i] = in.readLine();
System.out.print(i+1 + \"번째 사람 나이 = \");
age[i] = Integer.parseInt(in.readLine());
}
for(int i = 0; i < inwon; i++){
System.out.println(i+1 + \"번째 사람 이름 = \" + name[i]);
System.out.println(i+1 + \"번째 사람 나이 = \" + age[i]);
}
}
}
실행은 되는데 나이를 입력할때 오류가 나네요 ㅠㅠ
인원 = 2
1번째 사람 이름 = 버닝
1번째 사람 나이 = 23
Exception in thread \"main\" java.lang.NumberFormatException: For input string: \" 23\"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:449)
at java.lang.Integer.parseInt(Integer.java:499)
at Exam_01.main(Exam_01.java:18)
이런 오류가 나는데 이유가 머죠
public class Exam_01{
public static void main(String[] ar) throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int inwon = 0;
String[] name = null;
int[] age = null;
System.out.print(\"인원 = \");
inwon = Integer.parseInt(in.readLine());
name = new String[inwon];
age = new int[inwon];
for(int i = 0; i < inwon; i++){
System.out.print(i+1 + \"번째 사람 이름 = \");
name[i] = in.readLine();
System.out.print(i+1 + \"번째 사람 나이 = \");
age[i] = Integer.parseInt(in.readLine());
}
for(int i = 0; i < inwon; i++){
System.out.println(i+1 + \"번째 사람 이름 = \" + name[i]);
System.out.println(i+1 + \"번째 사람 나이 = \" + age[i]);
}
}
}
실행은 되는데 나이를 입력할때 오류가 나네요 ㅠㅠ
인원 = 2
1번째 사람 이름 = 버닝
1번째 사람 나이 = 23
Exception in thread \"main\" java.lang.NumberFormatException: For input string: \" 23\"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:449)
at java.lang.Integer.parseInt(Integer.java:499)
at Exam_01.main(Exam_01.java:18)
이런 오류가 나는데 이유가 머죠
열라 친절하게 익셉션 잘 나와있는데 안읽어본거냐 못읽는거냐
열라 친절하게 익셉션 잘 나와있는데 안읽어본거냐 못읽는거냐2