# Exercise 3.3 - Algebra: Solve 2x2 Linear Equations

The program below is the solution to Liang's Introduction to Java (9th Edition) Chapter 3 Exercise 3.3. ```/**
*
* @Author: Aghatise Osazuwa
* Website: www.cscprogrammingtutorials.com
*/
import java.util.Scanner;

public class Ex03_03 {
public static void main(String[] args) {
// declare variables
double a, b, c, d, e, f, num1, num2, denom, x, y;

// create Scanner to read user input
Scanner input = new Scanner(System.in);

System.out.print("This program solves 2x3 system of linear equations. "
+ "\n\nFor example in the following equation 9x + 4y = -6 "
+ "\n                                      3x - 5y = -21"
+ "\na, b, c, d, e, f = 9, 4, 3, -5, -6, -21 respectively. "
+ "\nEnter each number separated by pressing space or enter.");

// prompt user to enter details
System.out.print("\n\nEnter a, b, c, d, e, f: ");
a = input.nextDouble();
b = input.nextDouble();
c = input.nextDouble();
d = input.nextDouble();
e = input.nextDouble();
f = input.nextDouble();

//calculate x and y
num1 = ((e * d) - (b * f));
num2 = ((a * f) - (e * c));
denom = ((a * d) - (b * c));

x = num1 / denom;
y = num2 / denom;

if (denom == 0) {
System.out.println("\nThe equation has no solution.");
} else {
System.out.println("x is " + x + " and y is " + y);
}
}
}
``` Program sample run
Click here to see other solutions to Introduction to Java Programming.