Answer to Question #270736 in Java | JSP | JSF for jjjj

Question #270736

Solution in java ONLY plz... FULL question can be found on the following link http://ntci.on.ca/compsci/java/ch5/5_9.html ---> question 12

----------------------------------------------------------------------------------

Write a program that will read an arbitrary number of sets of three integers. The program should prompt the user for sets of numbers and process them until the user submits the numbers 0 0 0. For each set of three numbers, the program should first print the values read. It should then decide whether or not the three numbers could represent the lengths of the sides of a triangle. If the numbers could not represent the lengths of sides of a triangle, an appropriate message should be printed. If they could, then the program should determine and state into which of the above classes the triangle would be placed.



1
Expert's answer
2021-11-24T00:41:21-0500
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (true) {
            System.out.println("Provide three side lengths - 0 0 0 to terminate.");
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            if (a == 0 && b == 0 && c == 0) {
                System.out.println("Program was terminated by user.");
                break;
            }

            // make a the biggest side
            if (a < b) {
                int tmp = a;
                a = b;
                b = tmp;
            }
            if (a < c) {
                int tmp = a;
                a = c;
                c = tmp;
            }

            if (a <= 0 || b <= 0 || c <= 0 || a >= b + c) {
                System.out.println("Triangle cannot be formed.");
            }
            else {
                String side, angle;
                if (a == b && a == c)
                    side = "equilateral";
                else if (a == b || a == c || b == c)
                    side = "isosceles";
                else
                    side = "scalene";

                int diff = a * a - b * b - c * c;
                if (diff == 0)
                    angle = "right";
                else if (diff > 0)
                    angle = "obtuse";
                else
                    angle = "acute";
                System.out.println("Triangle possible: " + side + " and " + angle + ".");
            }
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS