程序查不出问题 高手帮帮忙
import java.lang.Math.*;
public class Jacobi
{
public static void main(String[] args)
{
final int M=3;
double a[M][M]={ {10,-1,-2},
{-1,10,-2},
{-1,-1, 5} };
double b[M] = { 7.2, 8.3, 4.2 };
double x[M] = {0,0,0},y[M];
double s, max, eps = 0.000000001;
int k, i, j, N = 100;
k = 1;
while( k <N )
{
for ( i=0; i <M ; i++ )
{ s = 0;
for ( j=0; j <M; j++ )
if( j-I ) s += a[i][j] * x[j];
y[i] = ( b[i]-s) / a[i][i];
}
max = 0;
for ( i=0; i <M; i++ )
if( max < Math.abs( x[i]-y[i] ) ) max = Math.abs( x[i] - y[i] );
if ( max < eps ) break;
System.out.println( "k= "+ k );
for( i=0; i <M; i++ )
System.out.println( "y[i]= "+ y[i] );
System.out.println( "i= "+ i );
k++;
for( i=0; i <M; i++ ) x[i] = y[i];
}
if(k == N) { System.out.println( "ERROR! " ); return; }
printf( "k= "+ k );
for ( i=0; i < M; i++ ) System.out.println( "y[i]= "+ y[ i ] );
System.out.println( "i= "+ i );
}
}
错误提示:
---------- javac ----------
Jacobi.java:7: 需要 '] '
double a[M][M]={ {10,-1,-2},
^
Jacobi.java:10: 需要 '] '
double b[M] = { 7.2, 8.3, 4.2 };