A beautiful Pythagorean Triple Program
For Java tutorials click the linkhttps://wordpress-343193-1101484.cloudwaysapps.com/wrapper-classes-in-java
A Pythagorean Triple is a set of positive integers, a, b and c that fits the rule: a^2 + b^2 = c^2
So if the three numbers are 3, 4, and 5.
3^2 + 4^2 = 5^2
9 + 16 = 25
so it is a Pythagorean Triple
For Java tutorials click the link
Wrapper classes in JAVA
Write a program to check if the given numbers are Pythagorean triplets or not.
import java.io.*;
class pythagoras
{
public static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the base");
int base=Integer.parseInt(br.readLine());
System.out.println("Enter the height");
int height=Integer.parseInt(br.readLine());
System.out.println("Enter the hypotenuse");
int hypo=Integer.parseInt(br.readLine());
if(hypo*hypo==base*base+height*height)
{
System.out.println("A Pythagorean Triple");
}
else
{
System.out.println("Not a Pythagorean Triple");
}
}
}Output:
Enter the base
2
Enter the height
4
Enter the hypotenuse
5
Not a Pythagorean Triple
For core java tutorial click
https://www.youtube.com/user/trushnatej
Related Posts
Continue learning with these related articles
Sum of First n Natural Numbers in Java (Loop and Formula)
Find the sum of the first n natural numbers in Java with a for loop, a while loop and the formula n(n + 1)/2, with a dry run and the sums of even numbers, odd numbers, squares and cubes.
Prime Number Program in Java: Check a Number and Print Primes in a Range
Check whether a number is prime in Java by counting its factors, a faster square-root method with isPrime(), and a program that prints all prime numbers in a range.

Encapsulation, Access Specifiers and Scope of Variables in Java for ICSE Class 10
ICSE Class 10 Computer Applications notes on encapsulation: private, default, protected and public access, data hiding with getter and setter methods, instance vs static (class) variables, local variables and scope, with a solved BankAccount program.