ICSE Class 9 Computer Applications
Question 13 of 17
Conditional Constructs in Java — Question 13
Back to all questions 13
Question Question 13
Write a program in Java to accept three numbers and check whether they are Pythagorean Triplet or not. The program must display the message accordingly. [Hint: h2=p2+b2]
import java.util.Scanner;
public class KboatPythagoreanTriplet
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter 1st number: ");
int a = in.nextInt();
System.out.print("Enter 2nd number: ");
int b = in.nextInt();
System.out.print("Enter 3rd number: ");
int c = in.nextInt();
if (a * a + b * b == c * c ||
a * a + c * c == b * b ||
b * b + c * c == a * a)
System.out.println("Pythagorean Triplets");
else
System.out.println("Not Pythagorean Triplets");
}
}Output
