Skip to content

Instantly share code, notes, and snippets.

@c650
Created August 26, 2016 17:07
Show Gist options
  • Save c650/e5cb7069750d4504cafaeba4c88e7bb4 to your computer and use it in GitHub Desktop.
Save c650/e5cb7069750d4504cafaeba4c88e7bb4 to your computer and use it in GitHub Desktop.
CLI Quadratic Formula Calculator
public class Quadratic {
public static void main(String[] args) {
double a,b,c;
if (args.length != 3) {
System.out.println("Wrong number of Args.\nUsage: [a] [b] [c]");
System.exit(1);
}
a = Double.parseDouble(args[0]);
b = Double.parseDouble(args[1]);
c = Double.parseDouble(args[2]);
System.out.println( "Solution 1: " + (-b + Math.sqrt( b * b - (4 * a * c) )) / ( 2 * a ) );
System.out.println( "Solution 2: " + (-b - Math.sqrt( b * b - (4 * a * c) )) / ( 2 * a ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment