URI Problem 1045 Solution in Java

Problem Details Link

Solution:



import java.util.Scanner;

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @E-mail : md.parvez28@gmail.com
 * @Date : Oct 11, 2016
 * @Time : 3:31:17 PM
 */
public class Uri1045 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double a, b, c;
        a = sc.nextDouble();
        b = sc.nextDouble();
        c = sc.nextDouble();
        if (a > 0 && b > 0 && c > 0) {
            double abc[] = sortDecreasing(new double[]{a, b, c});
            a = abc[0];
            b = abc[1];
            c = abc[2];
            //if A ≥ B + C, write the message: NAO FORMA TRIANGULO
            if (a >= (b + c)) {
                System.out.println("NAO FORMA TRIANGULO");
            }
            //if A2 = B2 + C2, write the message: TRIANGULO RETANGULO
            else if ((a * a) == ((b * b) + (c * c))) {
                System.out.println("TRIANGULO RETANGULO");
            }
            //if A2 > B2 + C2, write the message: TRIANGULO OBTUSANGULO
            else if ((a * a) > ((b * b) + (c * c))) {
                System.out.println("TRIANGULO OBTUSANGULO");
            }
            //if A2 < B2 + C2, write the message: TRIANGULO ACUTANGULO
            else if ((a * a) < ((b * b) + (c * c))) {
                System.out.println("TRIANGULO ACUTANGULO");
            }
            
            //if the three sides are the same size, write the message: TRIANGULO EQUILATERO
            if (a == b && b == c  && c==a) {
                System.out.println("TRIANGULO EQUILATERO");
            }
            //if only two sides are the same and the third one is different, write the message: TRIANGULO ISOSCELES
            else if ((a == b && a != c) || (b == c && b != a) || (a == c && a != b)) {
                System.out.println("TRIANGULO ISOSCELES");
            }
        }
    }

    private static double[] sortDecreasing(double[] par) {

        for (int i = 0; i < par.length; i++) {
            for (int j = 0; j < par.length - 1; j++) {
                if (par[j] < par[j + 1]) {
                    double temp = par[j];
                    par[j] = par[j + 1];
                    par[j + 1] = temp;
                }

            }
        }
        return par;
    }
}

Comments

Popular posts from this blog

URI Problem 1094 Solution in Java

URI Problem 1099 Solution in Java

URI Problem 1012 Solution in Java