daily pastebin goal
69%
SHARE
TWEET

Cramer's Rule With If statements

a guest Sep 26th, 2016 118 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1.  
  2. /*
  3.  * Tony Silvestri
  4.  * 9/26/2016
  5.  * CSC-111 D01
  6.  * Example Problem
  7.  * Calculates Cramer's Formula Version 3 With Variables and Scanners
  8.  * silvestri@stcc.edu
  9.  *
  10.  * Use this site to check:
  11.  * http://www.wolframalpha.com/widgets/view.jsp?id=b42a80c01d9b3bb5bb385d4fba81a0c5
  12. */
  13.  
  14. import java.util.Scanner;
  15.  
  16. public class Cramer {
  17.     public static void main(String args[]) {
  18.         final String TITLE = "Cramer's Rule Calculator V3.0";
  19.         System.out.println("Welcome to " + TITLE);
  20.  
  21.         double a, b, c, d, e, f;
  22.        
  23.  
  24.         // ax + by = e
  25.         // cx + dy = f
  26.         // Enter 5 5 10 10 10 21
  27.  
  28.         Scanner input = new Scanner(System.in);
  29.         System.out.print("Enter a: ");
  30.         a = input.nextDouble();
  31.         System.out.print("Enter b: ");
  32.         b = input.nextDouble();
  33.         System.out.print("Enter c: ");
  34.         c = input.nextDouble();
  35.         System.out.print("Enter d: ");
  36.         d = input.nextDouble();
  37.         System.out.print("Enter e: ");
  38.         e = input.nextDouble();
  39.         System.out.print("Enter f: ");
  40.         f = input.nextDouble();
  41.         input.close();
  42.         System.out.println();
  43.  
  44.         double denom = a * d - b * c;
  45.  
  46. //      if (cond)
  47. //          true_code;
  48. //      else
  49. //          false_code;
  50.        
  51.         if (denom == 0) {
  52.             System.out.println("Bad Input Values.  Cannot Calculate");
  53.         }
  54.         else {
  55.             double x, y;
  56.             x = (e * d - b * f) / denom;
  57.             y = (a * f - e * c) / denom;
  58.  
  59.             double xDisp = (int) (x * 1000.0 + 0.5) / 1000.0;
  60.             double yDisp = (int) (y * 1000.0 + 0.5) / 1000.0;
  61.  
  62.             System.out.println("X = " + xDisp);
  63.             System.out.println("Y = " + yDisp);
  64.         }
  65.  
  66.         System.out.println("Thank you for using " + TITLE);
  67.     }
  68.  
  69. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top