Lambda101-Multiplos-comandos-2

cleutonsampaio · updated September 24, 2019 · Java
import java.util.*;
import java.lang.*;
import java.io.*;

// Lambda 101: Multiplos comandos

/**
 * Esta eh uma interface funcional, pois possui apenas um metodo abstrato.
 */ 
interface Bhaskara {
    public double delta(double a, double b, double c);
}

interface Raiz {
    public double [] calcular(double a, double b, double c);
}


class Main {
    public static void main(String[] args) {
        
        // 2x2 + 8x - 24 = 0
        Bhaskara bas = (a,b,c) -> Math.pow(b,2)-4*a*c;
        Raiz raiz = (a,b,c) -> {double x1=0.0; double x2=0.0; double d=bas.delta(a,b,c); if (d>0) {x1=(-b+Math.sqrt(d))/(2*a); x2=(-b-Math.sqrt(d))/(2*a);}; return new double []{x1,x2};};
        System.out.println(Arrays.toString(raiz.calcular(2.0,8.0,-24.0)));
    }
}

Comments

Please sign up or log in to contribute to the discussion.