Created
September 1, 2017 07:43
-
-
Save hyperion0201/b325de2c67179af4d0ba1e44ab55ec3e to your computer and use it in GitHub Desktop.
Equal level 2 solution (JAVA)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import javax.swing.*; | |
import java.lang.Math.*; | |
import java.text.*; | |
class Eqn2 { | |
public static void Solve(int a, int b, int c) { | |
double delta = b*b-(4*a*c); | |
if (delta < 0) { | |
System.out.println("No solution !"); | |
} | |
if(delta == 0) { | |
double x = (-b)/(2*a); | |
System.out.println("Root : " + x); | |
} | |
if (delta > 0) { | |
double x1 = (-b + Math.sqrt(delta)) / 2*a; | |
double x2 = (-b - Math.sqrt(delta)) / 2*a; | |
DecimalFormat df = new DecimalFormat("0.000"); | |
System.out.println("Root 1: " + df.format(x1)); | |
System.out.println("Root 2: " + df.format(x2)); | |
} | |
} | |
public static void main(String[] args) { | |
Scanner scan = new Scanner(System.in); | |
System.out.print("Input a, b, c :"); | |
int j = scan.nextInt(); | |
int k = scan.nextInt(); | |
int l = scan.nextInt(); | |
Solve(j, k, l); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment