Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a method called printTriangleType that accepts three integer arguments rep

ID: 3623341 • Letter: W

Question

Write a method called printTriangleType that accepts three integer arguments representing the lengths of the sides of a triangle and prints what type of triangle it is. The three types are equilateral, isosceles, and scalene. An equilateral triangle has all three sides the same length, an isosceles triangle has two sides the same length, and a scalene triangle has three sides of different lengths. Here are some example calls to printTriangleType:

printTriangleType(5, 7, 7);
printTriangleType(6, 6, 6);
printTriangleType(5, 7, 8);
printTriangleType(12, 18, 12);
The output produced should be the following:

isosceles
equilateral
scalene
isosceles

Explanation / Answer

Please be sure to make sure you understand the code. It'll be easier to understand if you look at it for the concept and try to reproduce it on your own.

public void printTriangleType(int a, int b, int c){
    if (a == b){
        if (b == c)
            System.out.println("equilateral");
       else
           System.out.println("isoceles");
       return;
    }
    if (a == c){
       System.out.println("isoceles");
    return;
    }
    if (b == c){
        System.out.println("isoceles");
    return;
    }
    System.out.println("scalene");
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote