DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Find Min/Max Of A Porabola
// Short snippet that takes 3 integers and gives you the min/max location of a parabola
public class mainClass2 {
//Finds parabola min/max
public static void main(String args[]){
int a = 29;
int b = -31;
int c = 99;
float x = findX(a,b);
float y = findY(a,b,c,x);
if (a < 0){
System.out.println("max: x="+ x + " y=" + y);
}
else{
System.out.println("min: x="+ x + " y=" + y);
}
}
public static float findX(float a, float b){
if (a == 0){
return -1;
}
else{
return (-b)/(2*a);
}
}
public static float findY(float a, float b, float c, float x){
return a*(x*x) + (b*x) + c;
}
}






Comments
Snippets Manager replied on Mon, 2012/01/30 - 4:50pm
Snippets Manager replied on Mon, 2012/01/30 - 4:50pm