程序检查出现了这个:Exception in thread "main" java.lang.NullPointerException at test.Circle.setCircle(Circle.java:12) at test.Circle.main(Circle.java:36)程序:package test;import java.util.Scanner;public class Circle { /** * @param args */ int[] centre=new int[2]; int r; public void setCircle()throws Exception{ Circle[] a=new Circle[5]; a[0].centre[0]=0; a[0].centre[1]=0; a[0].r=1; for(int i=1;i<5;i++){ System.out.println("***请输入第"+(i+1)+"个圆的信息:***"); Scanner input =new Scanner(System.in); for(int j=0;j<2;j++){ System.out.println("圆心:"); a[i].centre[j]=input.nextInt(); } System.out.println("半径::"); a[i].r=input.nextInt(); } Circle x=new Circle(); x.receiveCircle(a); } public void receiveCircle(Circle[]a){ for(int i=0;i<5;i++){ System.out.println("圆心:"+"("+a[i].centre[0]+","+a[i].centre[1]+")"+" "+"半径:"+a[i].r); } } public static void main(String[] args) throws Exception { // TODO Auto-generated method stub Circle y=new Circle(); y.setCircle(); }}
添加回答
举报
0/150
提交
取消