How do I calculate the perimeter of a triangle in java?

Asked

Viewed 1,686 times

1

How do I calculate the perimeter of a triangle in java? I don’t know how to calculate the perimeter of a triangle in java, anyone knows? I tried but I could not, help me!

  • 1

    Post the code you have so far, tell if it is a method to calculate the perimeter just passing the values or is something more complex

  • 1

    Any type of triangle? put the source code even wrong, and detail the problem.

  • 1

    To calculate the perimeter of a triangle just add up the sides of it. How to do this in Java depends a lot on how your Triangulo class is doing. Post her here that gets easier to help.

1 answer

2

public class Triangulo {

    private final double lado1;
    private final double lado2;
    private final double lado3;

    public Triangulo(double lado1, double lado2, double lado3) {
        this.lado1 = lado1;
        this.lado2 = lado2;
        this.lado3 = lado3;
    }

    public double getPerimetro() {
        return lado1 + lado2 + lado3;
    }

    @Override
    public String toString() {
        return "Triangulo [lado1=" + lado1 + ", lado2=" + lado2 + ", lado3=" + lado3 + "]";
    }

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.