forked from cs-dept-ibbul/java2019
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab5Quadratic.java
More file actions
43 lines (32 loc) · 1013 Bytes
/
Copy pathLab5Quadratic.java
File metadata and controls
43 lines (32 loc) · 1013 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package assignment;
/**
*
* @author
*/
public class Quadratic
{
public static void main(String[] args)
{
/*Suppose our Quadratic Equation to be solved
* is 2x2 + 6x + 4 = 0 .
* (Assuming that both roots are real valued)
*
* General form of a Quadratic Equation is
* ax2 + bx + c = 0 where 'a' is not equal to 0
*
* Hence a = 2, b = 6 and c = 4.
*/
int a = 3;
int b = 7;
int c = 9;
//Finding out the roots
double root1 = (-b + Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2*a) ;
double root2 = (-b - Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2*a) ;
System.out.println(root1);
}
}