Question: Consider the following conditional statement for which int variables side1, side2, and side3 have previously been declared and assigned values. It will help us determine

Consider the following conditional statement for which int variables side1, side2, and side3 have previously been declared and assigned values. It will help us determine whether sticks with lengths side1, side2, and side3 can be used to make a triangle because the sum of the lengths of any two sides must be greater than the length of the third side.

boolean triangle = true; if (side1 + side2 <= side3) { triangle = false; } if (side1 + side3 <= side2) { triangle = false; } if (side2 + side3 <= side1) { triangle = false; }

System.out.println("Do we have a triangle? " + triangle); Answer the following questions.

For each of the following two cases, what is printed out?

a) the value of side1 is 27, the value of side2 is 12, and the value of side3 is 41

b) the value of side1 is 8, the value of side2 is 12, and the value of side3 is 6

If any of the sides have a negative or zero value, we can never form a triangle. Describe how you would modify the code to print out "No triangle is possible" when that happens.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!