import java.util.Locale;
import javax.swing.*;
class gauss
{ 
  public static double[] gauss(double a[][],double b[])
  {
  int n=a.length;	  
  double x[]=new double[n];
  double multiplier=0;
  double total=0;
  int i,j,k;
  for(k=0;k<(n-1);k++)
  {
    for(i=k+1;i<n;i++)
    {  multiplier=a[i][k]/a[k][k];
       a[i][k]=0;
       for(j=k+1;j<n;j++)
       {   a[i][j]-=multiplier*a[k][j];  }
       b[i]   =b[i]   -multiplier*b[k];
    }        
  }
  x[n-1]=b[n-1]/a[n-1][n-1];
  for(i=n-2;i>=0;i--)
  {
    total=0;
    for(j=i+1;j<n;j++)
    {  total+=a[i][j]*x[j];}
    x[i]=(b[i]-total)/a[i][i];
  }
  return x;
  }
  
 public static String toString(double a[][],double b[])
 {  Locale tr=new Locale("US");
    double V[]=gauss(a,b);
	int n=V.length;
    String s1="";
    for(int i=0;i<n;i++)
    { s1+=String.format(tr," %10.5f ",V[i]);}
    s1+="\n";
    return s1;
 }  	 
  public static void main(String args[]) 
  {
  double a[][]={{1,2,5},{2,1,2},{3,1,1}};
  double b[]={1,1,2};
  String s1="Solution of lineer system of equation by gauss elimination method";
  String s=toString(a,b);
  JOptionPane.showMessageDialog(null,s,s1,JOptionPane.PLAIN_MESSAGE); 
  
  }

 }
