Programming Examples

Java to accept three numbers and check whether they are Pythagorean triples or not


Write a program in Java to accept three numbers and check whether they are  Pythagorean triples or not. The program must display the message accordingly .

A "Pythagorean Triple" is a set of positive integers, a, b and c that fits the rule:

a2 + b2 = c2

Solution

import java.util.*;
class PythagoreanTriples 
{
	public static void main(String arr[])
	{
		int a,b,c;
		Scanner sc=new Scanner(System.in);
		System.out.print("Enter any 3 Number : ");
		a=sc.nextInt();
		b=sc.nextInt();
		c=sc.nextInt();
		if((Math.pow(a,2)+Math.pow(b,2))==Math.pow(c,2))
		{
			System.out.print("Number are Pythagorean Triples");
		}
		else
		{
			System.out.print("Number are not Pythagorean Triples");
		}
	}
}
Output

Enter any 3 Number :

3

4

5

Number are Pythagorean Triples

---------------------------------------------------------

Enter any 3 Number :

2

4

6

Number are not Pythagorean Triples


CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Website development Company in Allahabad