-2

I want to do a program in Java to compare 2 triangles. It doesn't matter the order of the angles to compare it, and I know that I could do it with if statements, but is any other more efficient way to compare the 3 angles to another 3 angles, as it doesn't matter that the triangle is rotated, because is exactly the same? (in Java)

Abra
  • 19,142
  • 7
  • 29
  • 41
  • What is the expected result? – dcolazin Oct 01 '22 at 16:00
  • I just want to know if 2 triangles are equals. Even if they introduce for example: 90º 30º 30º and the other triangle 30º 30º 90º. As they are exactly the same triangle just rotated. But i dont want to use ifs as I will have to use a big amount of them – diego otero Oct 01 '22 at 16:04
  • Please provide enough code so others can better understand or reproduce the problem. – Community Oct 01 '22 at 18:12

1 Answers1

1
  • Put the angles for each triangle in a separate List.
  • Sort the two lists.
  • Check whether the two lists are equal.
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Test {
    public static void main(String[] args) {
        List<Double> first = new ArrayList<>(List.of(90.0, 30.0, 30.0));
        List<Double> second = new ArrayList(List.of(30.0, 30.0, 90.0));
        Collections.sort(first);
        Collections.sort(second);
        System.out.println(first.equals(second));
    }
}
Abra
  • 19,142
  • 7
  • 29
  • 41