Question

//////// ONLY JAVA ****

5. In a right triangle, the square of the length of one side is equal to the sum of the squares of the lengths of the other two sides. Write a program that prompts the user to enter the lengths of three sides of a triangle and then outputs a message indicating whether the triangle is a right triangle. (Have the user enter the lengths 3, 4, and 5).

//////// ONLY JAVA ****

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Java code to the given requirement:

import java.util.*;

public class TriangleChecker

{

public static void main(String[] args)

{

//Scanner class object to read input from keyboard

Scanner in=new Scanner(System.in);

//Prompting the user to enter lengths of 3 sides

System.out.print("Enter length of the first side: ");

int side1=in.nextInt();

System.out.print("Enter length of the second side: ");

int side2=in.nextInt();

System.out.print("Enter length of the third side: ");

int side3=in.nextInt();

//conditions to check

if( (side1*side1)==(side2+side3) )

{

System.out.println("Right Triangle");

}else if((side2*side2)==(side1+side3))

{

System.out.println("Right Triangle");

}else if((side3*side3)==(side1+side2))

{

System.out.println("Right Triangle");

}else

{

System.out.println("Not a Right Triangle");

}

}

}

Test case 1:

Enter length of the first side: 3
Enter length of the second side: 4
Enter length of the third side: 5
Right Triangle

Test case 2:

Enter length of the first side: 10
Enter length of the second side: 11
Enter length of the third side: 12
Not a Right Triangle

Add a comment
Know the answer?
Add Answer to:
//////// ONLY JAVA **** //////// ONLY JAVA **** 5. In a right triangle, the square of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In a right triangle, the square of the length of one side is equal to the...

    In a right triangle, the square of the length of one side is equal to the sum of the squares of the lengths of the other two sides. Write a program that prompts the user to enter the lengths of three sides of a triangle and then outputs a message indicating whether the triangle is a right triangle. If the triangle is a right triangle, output It is a right-angled triangle If the triangle is not a right triangle, output...

  • Write the java program: A right triangle can have sides whose lengths are all integers. The...

    Write the java program: A right triangle can have sides whose lengths are all integers. The set of three integer values for the length of the sides of a triangle is called a Pythagorean triple. The length of the three sides must satisfy the relationship that the sum of the squares of the sides is equal to the square of the hypotenuse. Write a Java application that prompts the user for an integer that represents the largest side value and...

  • (JAVA) Implement a Triangle class. Any triangle can be represented by its THREE sides. Therefore,...

    (JAVA) Implement a Triangle class. Any triangle can be represented by its THREE sides. Therefore, your class will have THREE private member variables → side1, side2 and side3. Use the double data type to represent the triangle sides. In addition, please provide public methods that perform the following FIVE tasks: ▪ An input method that obtains the appropriate values for the three sides from the user. While entering the values of the three sides, please remember the triangle property that...

  • help im alittle lost my teacher posted all this its suppose to be in C++ language....

    help im alittle lost my teacher posted all this its suppose to be in C++ language. can yoh leave comments ans type the code thank you Write a C++ program that accepts the lengths of three sides (a,b,c) of a triangle as input from the user Validate the user input, so that sides a, b, c can only be POSITIVE. The program output should indicate whether or not the triangle is an Equilateral Triangle, a Right Triangle, Isosceles which is...

  • PLEASE READ AND CODE IN BASIC C++ CODE. ALSO, PLEASE CODE USING THIS DO WHILE LOOP...

    PLEASE READ AND CODE IN BASIC C++ CODE. ALSO, PLEASE CODE USING THIS DO WHILE LOOP AND FORMAT: #include <iostream> using namespace std; int main() { //variables here    do { // program here             }while (true);    } Objectives To learn to code, compile and run a program containing SELECTION structures Assignment Write an interactive C++.program to have a user input the length of three sides of a triangle. Allow the user to enter the sides...

  • Java Please - Design and implement a class Triangle. A constructor should accept the lengths of...

    Java Please - Design and implement a class Triangle. A constructor should accept the lengths of a triangle’s 3 sides (as integers) and verify that the sum of any 2 sides is greater than the 3rd(i.e., that the 3 sides satisfy the triangle inequality). The constructor should mark the triangle as valid or invalid; do not throw an exception. Provide get and set methods for the 3 sides, and recheck for validity in the set methods. Provide a toString method...

  • Java programming 1. (Triangle class) Design a new Triangle class that extends the abstract GeometricObject class....

    Java programming 1. (Triangle class) Design a new Triangle class that extends the abstract GeometricObject class. Draw the UML diagram for the classes Triangle and GeometricObject and then implement the Triangle class. Write a test program that prompts the user to enter three sides of the triangle, a color, and a Boolean value to indicate whether the triangle is filled. The program should create a Triangle object with these sides and set the color and filled properties using the input....

  • Must be java code Project 2b: CalculatePerimeter You are to write code for the application CalculatePerimeter where the computer calculates and displays the perimeter of a triangle, provided the three...

    Must be java code Project 2b: CalculatePerimeter You are to write code for the application CalculatePerimeter where the computer calculates and displays the perimeter of a triangle, provided the three double values entered from keyboard input represent a triangle. If they don't, the computer should display the fact that (at least, in the case of non-positive input) one of the values does not form a valid triangle What makes a valid triangle? All sides must be positive and the sum...

  • Problem a (PA4a.java) Write a program to evaluate the area of a triangle given the lengths...

    Problem a (PA4a.java) Write a program to evaluate the area of a triangle given the lengths of its sides using Heron's Formula. Here is an outline: Get the three side lengths from the user (which might have decimal values): a, b, c. Check to ensure that the sides are valid for a triangle. Importantly, the sum of the lengths of any two sides must be larger than the length of the third side (you must check all three sides this...

  • 2. Write a program that prompts a user to enter the lengths of sides and angles...

    2. Write a program that prompts a user to enter the lengths of sides and angles for the two triangles described below. The program should calculate the length of the side of the triangle indicated below. Print the two answers to 3 decimal places onto the console screen Triangle 1 Read in the value of the angle, alpha, and the length, a, of the side indicated in the picture below. Calculate the length of the hypotenuse, c, of this right...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT