Computer Science, asked by LikithaGN, 8 months ago

write a program to input 3 integer and check whether it forms a Pythagorean triplet or not a set of three integers is said to be Pythagorean triplet if the sum of the squares of any two integers is equal to the square of the third integer example (3,4,5)(5,12,13)and(7,24,25)​

Answers

Answered by Anonymous
11

import java.util.Scanner;

class pythagorean_triplet {

   public static void main(String[] args) {

       int[] Numbers = new int[3];

       Scanner getInput = new Scanner(System.in);

       for (int i = 0; i < Numbers.length; i++) {

           System.out.println("Enter a number: ");

           Numbers[i] = getInput.nextInt();

       }

       int f = Numbers[0] * Numbers[0];

       int s = Numbers[1] * Numbers[1];

       int t = Numbers[2] * Numbers[2];

       if ((f + s) == t) {

           System.out.println("Yes, numbers " + Numbers[0] + ", " + Numbers[1] + " and " + Numbers[2]

                   + " are forming a pythagorean triplet.");

       } else {

           System.out.println("No, numbers " + Numbers[0] + ", " + Numbers[1] + " and " + Numbers[2]

                   + " are not forming a pythagorean triplet.");

       }

       getInput.close();

   }

}

/* This program is written in java. If you want in any other language reckon to tell me that. */

Similar questions