Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Tony Silvestri
- * 9/26/2016
- * CSC-111 D01
- * Example Problem
- * Calculates Cramer's Formula Version 3 With Variables and Scanners
- * silvestri@stcc.edu
- *
- * Use this site to check:
- * http://www.wolframalpha.com/widgets/view.jsp?id=b42a80c01d9b3bb5bb385d4fba81a0c5
- */
- import java.util.Scanner;
- public class Cramer {
- public static void main(String args[]) {
- final String TITLE = "Cramer's Rule Calculator V3.0";
- System.out.println("Welcome to " + TITLE);
- double a, b, c, d, e, f;
- // ax + by = e
- // cx + dy = f
- // Enter 5 5 10 10 10 21
- Scanner input = new Scanner(System.in);
- System.out.print("Enter a: ");
- a = input.nextDouble();
- System.out.print("Enter b: ");
- b = input.nextDouble();
- System.out.print("Enter c: ");
- c = input.nextDouble();
- System.out.print("Enter d: ");
- d = input.nextDouble();
- System.out.print("Enter e: ");
- e = input.nextDouble();
- System.out.print("Enter f: ");
- f = input.nextDouble();
- input.close();
- System.out.println();
- double denom = a * d - b * c;
- // if (cond)
- // true_code;
- // else
- // false_code;
- if (denom == 0) {
- System.out.println("Bad Input Values. Cannot Calculate");
- }
- else {
- double x, y;
- x = (e * d - b * f) / denom;
- y = (a * f - e * c) / denom;
- double xDisp = (int) (x * 1000.0 + 0.5) / 1000.0;
- double yDisp = (int) (y * 1000.0 + 0.5) / 1000.0;
- System.out.println("X = " + xDisp);
- System.out.println("Y = " + yDisp);
- }
- System.out.println("Thank you for using " + TITLE);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement