/* PROBLEM: Write a program (with one class and that too having only the "main" method) to compute the solution of system of 3 linear eqautions, A.x = b on three variables using Cramer's rule. You may assume that coefficient matrix is non-singular. */ import javabook.*; public class Cramer { public static void main(String[] arg) { int a11,a12,a13,a21,a22,a23,a31,a32,a33; int b11,b21,b31; int D1,D2,D3,D; MainWindow m_Window=new MainWindow(); InputBox input=new InputBox(m_Window,true); // Get the matrix A from user in row-major form a11 = input.getInteger("Give an integer value for a11"); a12 = input.getInteger("Give an integer value for a12"); a13 = input.getInteger("Give an integer value for a13"); a21 = input.getInteger("Give an integer value for a21"); a22 = input.getInteger("Give an integer value for a22"); a23 = input.getInteger("Give an integer value for a23"); a31 = input.getInteger("Give an integer value for a31"); a32 = input.getInteger("Give an integer value for a32"); a33 = input.getInteger("Give an integer value for a33"); // Input Matrix B b11 = input.getInteger("Give an integer value for b11"); b21 = input.getInteger("Give an integer value for b21"); b31 = input.getInteger("Give an integer value for b31"); // Calculate Determinants D1 = b11*(a22*a33-a23*a32)-a12*(b21*a33-a23*b31)+a13*(b21*a32-a22*b31); D2 = a11*(b21*a33-a23*b31)-b11*(a21*a33-a23*a31)+a13*(a21*b31-b21*a31); D3 = a11*(a22*b31-b21*a32)-a12*(a21*b31-b21*a31)+b11*(a21*a32-a22*a31); D = a11*(a22*a33-a23*a32)-a12*(a21*a33-a23*a31)+a13*(a21*a32-a22*a31); // Display the result OutputBox out=new OutputBox(m_Window); out.println("The solution is ......"); out.println("x1 = " + (double)D1/D); out.println("x2 = " + (double)D2/D); out.println("x3 = " + (double)D3/D); out.waitUntilClose(); } }