Error
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.
  • JHTMLicon not supported. File not found.

y __} __else{ ___systemoutprintlnmin

Find Min/Max of a Porabola
Monday, 30 January 2012 15:52
// 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;
}
}

Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/g-7PpoyvgIg/14557

 


Taxonomy by Zaragoza Online