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
https://java4school.com/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