public class caida_libre {

    static public void main(String args[]) {
        double vi=20, g = (float) 9.8, hmax;

        double A, B, C, D, t1, t2, aux;

        // a) Utilizando h = (vi^2 - vf^2)/(2*g)  la hmax ocurre cuando vf = 0

        hmax = (vi * vi / 2.0 / g);
        System.out.printf("La velocidad inicial es %f\n", vi);
        System.out.printf("La altura Maxima es %f\n\n", hmax);

        // b) Para h = hmax/2 Resolvemos
        // y = vi*t - 0.5*g*t^2 con h = hmax/2
        // 0.5*g t^2 - vi t + hmax/2 = 0

        A = 0.5*g;
        B = -vi;
        C= hmax/2.0;

        D = B*B - 4.0*A*C;

        if(D < 0) System.out.printf("No existe solucion al problema\n") ;
        else {
            t1 = (-B + Math.sqrt(D))/2.0/A;  // t = (- B +- (B^2 - 4AC)^0.5)/(2.0*A)
            t2 = (-B - Math.sqrt(D))/2.0/A;

            if(t1>t2) {
                aux = t1;
                t1 = t2;
                t2 = aux;
            }

            System.out.printf("El objeto esta a la altura h = %f  \n\n", C);
            System.out.printf("Cuando sube en t1 = %f y cuando baja en t2 = %f\n", t1, t2);
        }
    }
}
