(URI) Triângulo - Solução
import java.io.*;
import java.util.*;
import java.lang.*;
class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
Main processando = new Main();
processando.processa();
System.exit(0);
}
public boolean isATriangle(float n1, float n2, float n3) {
if (n1 > Math.abs(n2-n3) && Math.abs(n2+n3) > n1) {
return true;
}
return false;
}
public void processa() throws NumberFormatException, IOException {
Scanner sc = new Scanner(System.in);
float n1 = sc.nextFloat();
float n2 = sc.nextFloat();
float n3 = sc.nextFloat();
if (isATriangle(n1, n2, n3) && isATriangle(n2, n3, n1) && isATriangle(n3, n1, n2)) {
System.out.println("Perimetro = " + (n1+n2+n3));
}
else {
System.out.println("Area = " + String.format("%.1f", (((n1+n2)/2)*n3)));
}
return;
}
}
import java.util.*;
import java.lang.*;
class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
Main processando = new Main();
processando.processa();
System.exit(0);
}
public boolean isATriangle(float n1, float n2, float n3) {
if (n1 > Math.abs(n2-n3) && Math.abs(n2+n3) > n1) {
return true;
}
return false;
}
public void processa() throws NumberFormatException, IOException {
Scanner sc = new Scanner(System.in);
float n1 = sc.nextFloat();
float n2 = sc.nextFloat();
float n3 = sc.nextFloat();
if (isATriangle(n1, n2, n3) && isATriangle(n2, n3, n1) && isATriangle(n3, n1, n2)) {
System.out.println("Perimetro = " + (n1+n2+n3));
}
else {
System.out.println("Area = " + String.format("%.1f", (((n1+n2)/2)*n3)));
}
return;
}
}
Comments
Post a Comment