Write a program to input 3 nos. and check whether they are Pythogorean Triplet . or not .The program must display the message accordingly.
some Pythagorean triplets are
( 3, 4, 5)
( 5, 12, 13)
( 7, 24, 25)
( 8, 15, 17)
( 9, 40, 41)
(11, 60, 61)
(12, 35, 37)
(13, 84, 85)
(16, 63, 65)
(20, 21, 29)
(28, 45, 53)
(33, 56, 65)
(36, 77, 85)
(39, 80, 89)
(48, 55, 73)
(65, 72, 97)
u may use them to test the program.
Answer:
//program starts
import java.io.*;
class pytha
{
void main()throws IOException
{
BufferedReader obj=new BufferedReader(new InputStreamReader(System.in));
int a,b,c;
System.out.println("enter no.");
a=Integer.parseInt(obj.readLine());
System.out.println("enter no.");
b=Integer.parseInt(obj.readLine());
System.out.println("enter no.");
c=Integer.parseInt(obj.readLine());
if (a*a==b*b+c*c)
System.out.println("They are Pythogorean Triplet");
else if(b*b==a*a+c*c)
System.out.println("They are Pythogorean Triplet ");
else if(c*c==a*a+b*b)
System.out.println("They are Pythogorean Triplet a² + b² = c² ");
else
System.out.println("Test Failed !!! They are Non Pythogorean Triplet ");
}
}
//if u want to consider a² + b² = c² only then remove first 2 conditions
Showing posts with label Pythagorean triplets. Show all posts
Showing posts with label Pythagorean triplets. Show all posts
Wednesday, January 23, 2008
JAVA icse bluej program Pythagorean triplet
Posted by
Blogger 2.o
at
8:22 PM
0
comments
Labels: BLUEJ, BufferedReader, computer icse, computer program, for icse students, icse, ICSE 2008 Exam, isc, JAVA, JAVA program, JAVA related questions, Pythagorean triplets
Subscribe to:
Posts (Atom)