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

Snippets has posted 5883 posts at DZone. View Full User Profile

Find Min/Max Of A Porabola

01.30.2012
| 3245 views |
  • submit to reddit
        // 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

I've just added a post which finds x, y intercepts of a line

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

What other types of posts were you looking for?