this is a question from computer java can anyone help me to answer this question
Answers
Explanation:
Algorithm. Step 1: Declare three sides of triangle. Step 2: Enter three sides at run time. Step 3: If side1 == side2 && side2 == side3 Go to step 6 Step 4: If side1 == side2 || side2 == side3 || side3 == side1 Go to Step 7 Step 5: Else Go to step 8 Step 6: Print the triangle is equilateral.
Type of Triangle - Java
In Geometry, a triangle is a three-sided polygon with three edges and three vertices. A triangle with vertices A, B, and C denoted ΔABC.
A triangle is said to be an EQUILATERAL TRIANGLE if all the sides are equal in measure.
A triangle is said to be an ISOSCELES TRIANGLE if any two sides are equal in measure.
A triangle is said to be a SCALENE TRIANGLE if none of the sides are equal in measure.
Let's implement the same logic in the program to check the type of triangle.
Here's our program:
import java.util.Scanner; // Creating scanner class
public class Type_of_Traingle // Creating class
{
// The MAIN function
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Taking user input to accept the length of the first side of a triangle and storing it in double data type
System.out.print("Enter the length of the first side of a triangle: ");
double a = sc.nextDouble();
// Taking user input to accept the length of the first side of a triangle and storing it in double data type
System.out.print("Enter the length of the second side of a triangle: ");
double b = sc.nextDouble();
// Taking user input to accept the length of the first side of a triangle and storing it in double data type
System.out.print("Enter the length of the third side of a triangle: ");
double c = sc.nextDouble();
// Closing scanner class after the use
sc.close();
// If all sides of a trinagle are equal, it is a equilateral triangle
if (a == b && b == c) {
System.out.println("EQUILATERAL TRAINGLE.");
}
// If two sides of a trinagle are equal, it is a isosceles triangle
else if (a == b || b == c || a == c) {
System.out.println("ISOSCELES TRAINGLE.");
}
// If non of the sides of a triangle are equal, it is a scalene triangle
else if (a != b && b != c && a != c) {
System.out.println("SCALENE TRAINGLE.");
}
// If the inputs are invalid
else {
System.out.println("Invalid Input");
}
}
}