Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Write a description of class Equations here.
- *
- * @id xxxxxxxxx
- * @author Alon
- */
- import java.util.Scanner;
- public class Equations
- {
- public static void main(String[] args) {
- System.out.println("This program solves a system of 2 linear equations");
- System.out.println("Enter the coefficients a11 a12 a21 a22 b1 b2");
- Scanner scan = new Scanner(System.in);
- int a11 = scan.nextInt();
- int a12 = scan.nextInt();
- int a21 = scan.nextInt();
- int a22 = scan.nextInt();
- int b1 = scan.nextInt();
- int b2 = scan.nextInt();
- System.out.println("Eq1: " + a11 + "*x1+" + a12 + "*x2=" + b1);
- System.out.println("Eq2: " + a21 + "*x1+" + a22 + "*x2=" + b2);
- Boolean isOneResult = (a11*a22 - a12*a21) != 0;
- // Single solution
- if (isOneResult) {
- System.out.println("Single solution: (" + ((double)((b1*a22) - (b2*a12)) / ((a11*a22) - (a12*a21))) + "," +
- ((double)((b2*a11) - (b1*a21)) / ((a11*a22) - (a12*a21))) + ")");
- }
- } // end of class main
- } // end of class Equations
Add Comment
Please, Sign In to add comment