import java.util.Scanner;
class PointNode{
public int x,y;
public int tag;
}
public class test3 {
public static void main(String args[]){
Scanner scanner=new Scanner(System.in);
PointNode[] point=new PointNode[3];
for (int k = 0; k < 3; k++) {
point[k].x=scanner.nextInt();
point[k].y=scanner.nextInt();
}
for (int i = 0; i < 3; i++) {
System.out.println(point[i].x);
System.out.println(point[i].y);
}
}
}
------解决方案--------------------
point[k] = new Point(); 没有初始化
------解决方案--------------------
- Java code
import java.util.Scanner;class PointNode{ public int x,y; public int tag; } public class Test14 { public static void main(String args[]){ Scanner scanner=new Scanner(System.in); PointNode[] point=new PointNode[3]; for (int k = 0; k < 3; k++) { //要对数组每个元素实例化 point[k] = new PointNode(); point[k].x=scanner.nextInt(); point[k].y=scanner.nextInt(); } for (int i = 0; i < 3; i++) { System.out.println(point[i].x); System.out.println(point[i].y); } }}