Advertisement
LightProgrammer000

Classificacao_Triangulo

Feb 19th, 2020
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.94 KB | None | 0 0
  1. /*
  2. # Programa: Classificação de triângulo
  3. */
  4.  
  5. package Extra;
  6.  
  7. import java.util.Scanner;
  8.  
  9. public class EX_01
  10. {
  11.     public static void main(String[] args)
  12.     {
  13.         // Variaveis
  14.         int j = 0;
  15.         double vetor[] = new double[3];
  16.         String lista[] = {"A", "B", "C"};
  17.          
  18.         // Instanciacao
  19.         Scanner ent = new Scanner(System.in);
  20.        
  21.         // Estrutura de repeticao
  22.         for(int i = 0; i < 3; i++)
  23.         {
  24.             System.out.print("# Lado [" + lista[i] + "]: ");
  25.             vetor[i] = ent.nextDouble();
  26.         }
  27.         System.out.println("");
  28.        
  29.         // Estrutura de decisao
  30.         if(existencia_triangulo(vetor, lista, j))
  31.         {
  32.             System.out.println(class_triangulo(vetor, j));
  33.         }
  34.        
  35.         else
  36.         {
  37.             System.out.println("Nao pode formar triangulo");
  38.         }
  39.     }
  40.    
  41.     // Funcao: Existencia de triangulo
  42.     static boolean existencia_triangulo(double vetor[], String lista[], int j)
  43.     {
  44.         // Variaveiss
  45.         boolean regra_1, regra_2, regra_3;
  46.  
  47.         // Calculos booleanos
  48.         regra_1 = vetor[j] < vetor[j+1] + vetor[j+2];
  49.         regra_2 = vetor[j+1] < vetor[j] + vetor[j+1];
  50.         regra_3 = vetor[j+2] < vetor[j] + vetor[j+2];
  51.        
  52.         return regra_1 && regra_2 && regra_3;
  53.     }
  54.    
  55.     // Funcao: Classificacao de triangulo
  56.     static String class_triangulo(double vetor[], int j)
  57.     {  
  58.         // Variaveis
  59.         double a = vetor[j];
  60.         double b = vetor[j+1];
  61.         double c = vetor[j+2];
  62.        
  63.         // Estrutura de decisao
  64.         if(a == b && b == c)
  65.         {
  66.             return "Triangulo equilatero";            
  67.         }
  68.        
  69.         else if(a != b && b != c && c != a)
  70.         {
  71.             return "Triangulo escaleno";
  72.         }
  73.        
  74.         else
  75.         {
  76.             return "Triangulo isosceles";
  77.         }        
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement