public static void main(String args[])
{
System.out.print("请输入方程组的维数:");
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
String s="";
int N=0,K=0;
try{ s=in.readLine();N=Integer.parseInt(s);}catch(IOException e){}
float a[][]=new float[N][N+1];
System.out.print("请输入方程的各系数:\n");
for(int i=1;i<=N;i++)
{
for(int j=1;j<=N+1;j++)
{
System.out.print("a"+i+","+j+":");
try{
s=in.readLine();
a[i][j]=Float.parseFloat(s);
}catch(IOException e){System.out.println("a;fja");}
}
}
…………………………
…………………………
…………………………
}
}
}
输入数给a数组定初值时怎么输完四个后就出错呢?
请看如下运行结果:
C:\>java Jacobi
请输入方程组的维数:3
请输入方程的各系数:
a1,1:8
a1,2:-3
a1,3:2
a1,4:20
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at Jacobi.main(Jacobi.java:19)
C:\>javac Jacobi.java
C:\>java Jacobi
请输入方程组的维数:3
请输入方程的各系数:
a1,1:5
a1,2:6
a1,3:2
a1,4:5
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at Jacobi.main(Jacobi.java:21)
C:\>
C:\>