Last active
April 9, 2020 19:12
-
-
Save WandersonAlves/d29a26ebca54c288b6ea6d9b3a5deb3e to your computer and use it in GitHub Desktop.
Ifs com Helder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class condici { | |
public static void main(String[] args) { | |
Scanner input = new Scanner(System.in); | |
double l1, l2, l3; | |
System.out.println("É triângulo?"); | |
System.out.println("Lado 1:"); | |
l1 = input.nextDouble(); | |
System.out.println("Lado 2:"); | |
l2 = input.nextDouble(); | |
System.out.println("Lado 3:"); | |
l3 = input.nextDouble(); | |
if (this.isTriangle(this.l1, this.l2, this.l3)) { | |
System.out.println("É um triângulo"); | |
if (this.isTriangleEquilatero(this.l1, this.l2, this.l3)) { | |
System.out.println("O triângulo é equilátero"); | |
} else if (this.isTriangleIsoceles(this.l1, this.l2, this.l3)) { | |
System.out.println("O triângulo é isóceles"); | |
} else if (this.isTriangleEscaleno(this.l1, this.l2, this.l3) { | |
System.out.println("O triângulo é escaleno"); | |
} | |
} else { | |
System.out.println("Não é triângulo"); | |
} | |
input.close(); | |
} | |
public boolean isTriangle(double l1, double l2, double l3) { | |
return (l1 + l2 > l3) && (l2 + l3 > l1) && (l1 + l3 > l2); | |
} | |
public boolean isTriangleEquilatero(double l1, double l2, double l3) { | |
return l1 == l2 && l2 == l3; | |
} | |
public boolean isTriangleIsoceles(double l1, double l2, double l3) { | |
return (l1 == l2 && l2 != l3) || (l1 != l2 && l1 == l3) || (l2 == l3 && l3 != l1); | |
} | |
public boolean isTriangleEscaleno(double l1, double l2, double l3) { | |
return l1 != l2 && l2 != l3; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment