-1
我想首先採取整數N後跟N行,其中每行有兩個座標x和y。 (以空格分隔)。我嘗試過,但它給NullPointerException
。輸入閱讀輸入分隔空間
class solution{
class Point{
int x;
int y;
}
public static void main(String[] args) throws IOException {
int N;
Scanner in = new Scanner(System.in);
BufferedReader inp = new BufferedReader (new InputStreamReader(System.in));
N=Integer.parseInt(in.next());
Point[] P = new Point[N];
for(i=0;i<N;i++){
String[] s1 = inp.readLine().split(" ");
P[i].x=Integer.parseInt(s1[0]);
P[i].y=Integer.parseInt(s1[1]);
}
}
例如:
4
2 4
5 7
8 9
1 0
爲什麼你使用'Scanner'和'BufferedReader'呢?使用其中任何一個。 –
好的,你能告訴我們你在哪一行得到NullPointerException? – Ajeesh
@RohitJain只能去練習..並且請不要做任何作業 – user119249