0

Java Program to Check for Right Angled Triangle

 1 year ago
source link: https://hackernoon.com/java-program-to-check-for-right-angled-triangle
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Java Program to Check for Right Angled Triangle

Notifications
Start Your Week by Reading More About Inhabitants Unknown to Earth, The Value of Bitcoin in 2140 and The Threats of Metaverse!
Last Monday at 7:13 AM
Happy Weekend, enjoy these top stories from this week, The Machine, Keeping Cows, and more 💚
Last Saturday at 6:00 PM
#Noonies voting closes on November 15th! Vote now for your favorite tech-pioneers!
10/13/2022
Discover Trending Tech Companies via Tech Company Brief
10/13/2022
Highlight any text on a story and HackerNoon will generate beautiful quote images for you to share!
10/11/2022
Happy Weekend, enjoy these top stories from this week, Contagion, House Robber, and more 💚
10/08/2022
Over 100,000 votes have been casted for this year’s Noonies Nominees. Vote for your favorite now!
10/03/2022
There have been over 90,000 votes cast in this year's Noonies! Vote for your favorite tech stars today
09/26/2022
Vote now on HackerNoon weekly polls!
09/22/2022
Start off your week the right way! Enjoy the top stories put out by the beautiful people of HackerNoon!
09/20/2022
Don't miss out on the daily top trending stories on HackerNoon! Subscribe to TechBeat to see what people are currently interested about!
09/20/2022
Do you know #Noonies voters can also win a free .Tech Domain? For details, check your email after casting the vote.
09/12/2022
The Sandbox is back with #EnterTheMetaverse Writing Contest. Win from $18,000 prize pool!
09/12/2022
HackerNoon now publishes sci-fi! Read some of our science fiction stories today and submit your own!
09/05/2022
$200k+ in Committed Writer Payouts for HackerNoon Writing Contests. Enter to Win Monthly Prizes!
08/29/2022
The Blockchain Writing Contest 2022: Round 5 Results Announced!
08/18/2022
mParticle and HackerNoon brings you the Growth Marketing Writing Contest starting from September!
08/08/2022
see 10 more
Java Program to Check for Right Angled Triangle by@mayankvikash

Java Program to Check for Right Angled Triangle

October 21st 2022 new story
3 min
by @mayankvikash

Mayank Vikash

@mayankvikash

Student with some knowledge of how technologies work.

Open TLDRtldt arrow
Read on Terminal Reader
Read this story in a terminal

Too Long; Didn't Read

A right-angled triangle is a triangle with one of its interior angles equal to 90 degrees or any one angle is a right angle. Pythagoras’s Theorem is mentioned in the Baudhayana Sulba-sutra of India, which was written between 800 and 400 BCE. The square of the hypotenuse is equal to the sum of the squared of the squares of the other two sides of a triangle. If the square is equal, the triangle is left-angled.
image
Your browser does not support theaudio element.
Read by Dr. One (en-US)
Audio Presented by

Mayank Vikash

Student with some knowledge of how technologies work.

Learn More
LEARN MORE ABOUT @MAYANKVIKASH'S EXPERTISE AND PLACE ON THE INTERNET.

A right-angled triangle is a triangle with one of its interior angles equal to 90 degrees or any one angle is a right angle.

There are several properties of a right-angled triangle; one of them is that the square of the hypotenuse is equal to the sum of the square of the perpendicular and base of a triangle. This is called the Pythagoras Theorem.

The hypotenuse is the longest side of a triangle.

Fun Fact: Pythagoras’s Theorem was invented in India, long before Pythagoras was even born.

The theorem is mentioned in the Baudhayana Sulba-sutra of India, which was written between 800 and 400 BCE.

Program’s Logic

According to the theorem, the squared of Hypotenuse is equal to the sum of the squared of the other two sides. So, we have to take the input of the two sides of a triangle and a hypotenuse. Calculate the sum of squares of the other two sides and if the sum is equal to the square of the hypotenuse, the triangle is right-angled.

Program’s Screenshot:

Screenshot of the program

Let’s write the program

Basic program structure:

import java.util*;
public class RightAngledTriangle{
  public static void main(String args[]){
    Scanner in = new Scanner(System.in);
    // code
  }
}

Declaring variables:

int h, p, b;

Asking the user for input:

System.out.println("Enter the Hypotenuse");
h = in.nextInt();
System.out.println("Enter the Perpendicular");
p = in.nextInt();
System.out.println("Enter the Base");
b = in.nextInt();

The simple way to check if the squared of the hypotenuse is equal to the sum of the squared of the perpendicular and base is to use if-else.

If-else condition:

if (h*h==(p*p)+(b*b)){
    System.out.println("Right Angled Triangle");
}
else{
    System.out.println("Not a right angled Traingle");
}
import java.util.*;
public class RightAngledTriangle {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int h, p, b;
        System.out.println("Enter the Hypotenuse");
        h = in.nextInt();
        System.out.println("Enter the Perpendicular");
        p = in.nextInt();
        System.out.println("Enter the Base");
        b = in.nextInt();

        if (h*h==(p*p)+(b*b)){
            System.out.println("Right Angled Triangle");
        }
        else{
            System.out.println("Not a right angled Traingle");
        }

    }
}

Output

Not a right-angled triangle

Right-angled triangle


Also published here.

by Mayank Vikash @mayankvikash.Student with some knowledge of how technologies work.
Read my stories
L O A D I N G
. . . comments & more!

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK