Advertisement
therrontelford

Cramer's Rule

Nov 12th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Chapter3_3CramersRule {
  3.  
  4.     public static void main(String[] args) {
  5.         Scanner kb = new Scanner (System.in);
  6.         System.out.println("Enter a,b,c,d,e,and f");
  7.         double a = kb.nextDouble();
  8.         double b = kb.nextDouble();
  9.         double c = kb.nextDouble();
  10.         double d = kb.nextDouble();
  11.         double e = kb.nextDouble();
  12.         double f = kb.nextDouble();
  13.         double x = 0;  // you must initialize the variable to something.  0 is good in this case
  14.         double y = 0;  // you must initialize the variable to something.  0 is good in this case
  15.  
  16.         if ((a*d - b*c) !=0){
  17.             x = (e*d - b*f)/(a*d - b*c);
  18.             y = (a*f - e*c)/(a*d - b*c);
  19.             System.out.println("x is "+ x + " and y is "+ y);
  20.         }
  21.         else
  22.             System.out.println("The equation has no solutions");
  23.     }
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement