Skip to content

Instantly share code, notes, and snippets.

@hyperion0201
Created September 1, 2017 07:43
Show Gist options
  • Save hyperion0201/b325de2c67179af4d0ba1e44ab55ec3e to your computer and use it in GitHub Desktop.
Save hyperion0201/b325de2c67179af4d0ba1e44ab55ec3e to your computer and use it in GitHub Desktop.
Equal level 2 solution (JAVA)
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