Java Program for Pythagorean Triples

In this example, You learn about Java program for Pythagorean Triples. 

Here you learn pythagorean triplet in Java, You are given a numbers and the task of the program to deduce whether the given numbers form a right angled triangle or not i.e. pythagorean triplet in Java.

A Pythagorean Triples are the three positive integers a, b, and c such that a2 + b2 = c2. Here a id perpendicular, b is base and c is hypotenuse.

Java Program for Pythagorean Triples



import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    int a = scn.nextInt();
    int b = scn.nextInt();
    int c = scn.nextInt();

    int max = a;
    if (b >= max)
      max = b;

    if (c >= max)
      max = c;

    if (max == a) {
      System.out.println((b * b + c * c) == (a * a));
    } else if (max == b) {
      System.out.println((a * a + c * c) == (b * b));
    } else {
      System.out.println((a * a + b * b) == (c * c));
    }
  }
}

Output


 3 4 5
 true


In the above article, I shared Java program for Pythagorean Triples. If you know something new then please comment or send mail to featured and for contribution to codeamy.in and I also share java program soon.


Happy Coding!! 😊

If you have any doubts, Please let me know

Previous Post Next Post

Contact Form