any help would be great Read three sides (integers) and identify the type of tri
ID: 3550165 • Letter: A
Question
any help would be great
Read three sides (integers) and identify the type of triangle. When the first side length is input, check whether the value is odd or even and print it out . When the second side length is input, check whether the side is equal/1 onger/shorter than the first side and print it out . When the third side is input, compare all three values and print out three sides from longest to the shortest order . Once the three sides are input, identify a type of triangle from the list below. The definitions of triangle types are also described.Explanation / Answer
import java.util.Scanner;
public class task2 {
public static void main (String [] args) {
double a = 0,b=0,c=0,side1=0,side2=0,side3=0;
Scanner input = new Scanner(System.in);
System.out.println("*** Task1:Identify the triangle ***");
System.out.println("Please input for first podouble, X and Y: ");
double side1x = input.nextDouble();
double side1y = input.nextDouble();
System.out.println("("+side1x +","+side1y+") is the position");
System.out.println("Please input for second podouble, X and Y: ");
double side2x = input.nextDouble();
double side2y = input.nextDouble();
System.out.println("("+side2x +","+side2y+") is the position");
System.out.println("Please input for third podouble, X and Y: ");
double side3x = input.nextDouble();
double side3y = input.nextDouble();
System.out.println("("+side3x +","+side3y+") is the position");
//find length of sides of triangle
side1 = Math.sqrt(Math.pow((side2x - side1x),2) + Math.pow((side2y - side1y),2));
side2 = Math.sqrt(Math.pow((side3x - side2x),2) + Math.pow((side3y - side2y),2));
side3 = Math.sqrt(Math.pow((side1x - side3x),2) + Math.pow((side1y - side3y),2));
if(side1>side2 && side1>side3){
a=side1;
b=side2;
c=side3;}
else if(side2>side1 && side2>side3){
a=side2;
b=side1;
c=side3;}
else{
a=side3;
b=side1;
c=side2;
}
if(a==b && a==c){
System.out.println("The triangle is Equilateral");
}else if(a==b || a==c || b==c){
System.out.println("The triangle is Isoceles");
}
if(a*a == (b*b)+(c*c)){
System.out.println("It is a right angle triangle");
}else if(a*a > (b*b)+(c*c)){
System.out.println("It is Obtuse triangle");
}else if(a*a < (b*b)+(c*c)){
System.out.println("It is an acute triangle");
}
if(a>(b+c)){
System.out.println("Invalid triangle");
}
}}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.