-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise03_01.java
More file actions
38 lines (36 loc) · 1.24 KB
/
Copy pathExercise03_01.java
File metadata and controls
38 lines (36 loc) · 1.24 KB
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
package Chapter3;
/*
* 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.
*/
import java.util.Scanner;
/**
*
* @author jorda
*/
public class Exercise03_01 {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Enter a: ");
double a = input.nextDouble();
System.out.print("Enter b: ");
double b = input.nextDouble();
System.out.print("Enter c: ");
double c = input.nextDouble();
double answer, rootOne, rootTwo;
answer = Math.pow(b, 2) - 4 * a * c;
if(answer > 0){
System.out.print("There are two real roots:");
rootOne = (-b + Math.pow(answer, 0.5))/(2*a);
rootTwo = (-b - Math.pow(answer, 0.5))/(2*a);
System.out.print(rootOne + " and " + rootTwo);
}else if (answer == 0){
System.out.print("There is one real root: ");
rootOne = (-b + Math.pow(answer, 0.5))/(2*a);
System.out.println(rootOne);
}else if (answer < 0){
System.out.println("There are no real roots");
}
}
}