View the main link :
https://www.urionlinejudge.com.br/judge/en/problems/view/1043
URI Online Judge | 1043
Triangle
Adapted by Neilor Tonin, URI Brazil
Timelimit: 1
Read three point floating values (A, B and C) and verify if is possible to make a triangle with them. If it is possible, calculate the perimeter of the triangle and print the message:
Perimetro = XX.X
If it is not possible, calculate the area of the trapezium which basis A and B and C as height, and print the message:
Area = XX.X
Input
The input file has tree floating point numbers.
Output
Print the result with one digit after the decimal point.
Input Sample | Output Sample |
6.0 4.0 2.0 | Area = 10.0 |
6.0 4.0 2.1 | Perimetro = 12.1 |
URI 1043 Solution in Java language:
package URI_Problems_solution; /** 6.0 4.0 2.0 Area = 10.0 6.0 4.0 2.1 Perimetro = 12.1 */ import java.util.Scanner; public class URI_1043 { public static void main(String[] args) { float A, B, C, areaTraphisium, perimeterTriangle ; Scanner input =new Scanner(System.in); A = input.nextFloat(); B = input.nextFloat(); C = input.nextFloat(); if ((A < (float)(B+C)) && (B < (float)(A+C)) && (C < (float)(B+A))) { //Triangle perimeter = a + b + c; //Traphisium area is = (a + b)*h/2 perimeterTriangle = A + B + C; System.out.printf("Perimetro = %.1f\n",perimeterTriangle); }else { areaTraphisium = ((A + B) * C) / 2; System.out.printf("Area = %.1f\n",areaTraphisium); } } }
No comments:
Write commentsTo know more about the problem, give us your valuable commment. We'll try to help you. Thanks