Write me a function that receives three integer inputs [требует правки]

244
04 февраля 2018, 01:05

Write me a function that receives three integer inputs for the lengths of the sides of a triangle and returns one of four values to determine the triangle type (1=scalene, 2=isosceles, 3=equilateral, 4=error).

Answer 1
/*****************************************************************
  Method: getTriangleType()
  Input: three integer sides a, b, c.
  Return: 1 - scalene, 2 - isosceles, 3 - equilateral, 4 - error.
*****************************************************************/
public int getTriangleType(int a, int b, int c) {
  if ((a + b) < c) {
  /* If sum of any of two sides less than third side, than it cannot be
     a triangle. I chose (a + b) < c, but (a + c) < b or (b + c) < a would 
     work too. */
     return 4;
  } else if(a == b || a == c || b == c) {
  /* If two of the three sides are equal than we check for equilateral. */
     if (a == b && a == c) {
        /*Here you can also use (b == a && b == c) or (c == a && c == b). */
        return 3;
     } else {
        /* If it is not equilateral, than it is isosceles*/
        return 2;
     }
  } else {
     /* Only scalene triangle left. */
     return 1;
  }
}
READ ALSO
Как определить тип дженерик аргумента в java?

Как определить тип дженерик аргумента в java?

Можно ли собственно получить тип N наподобиеgetClass()

264
Как проверить играет ли музыка в mediaPlayer?

Как проверить играет ли музыка в mediaPlayer?

Пробовал использовать этот код, но ничего не заработалоМожет есть еще способы, как проверить играет ли музыка?

265
Удаление символов из строки java

Удаление символов из строки java

Есть список ненужных символов, допустим String taboo = "1234567890!@#$%^&*()_+!№;%:?*/\\\"~";`

302