Skip to main content

Posts

Showing posts with the label pythagorean triplet java solution

Pythagorean Triplet in Java (EASY)

Question: Given an array of integers, write a function that returns true if there is a triplet (a, b, c) that satisfies a 2  + b 2  = c 2 . Input: The first line contains 'T' denoting the number of testcases. Then follows description of testcases. Each case begins with a single positive integer N denoting the size of array. The second line contains the N space separated positive integers denoting the elements of array A. Output: For each testcase, print "Yes" or  "No" whtether it is Pythagorean Triplet or not. Constraints: 1<=T<=50  1<=N<=100  1<=A[i]<=100 Example: Input: 1 5 3 2 4 6 5 Output: Yes Solution: import java.util.*; import java.lang.*; import java.io.*; import java.math.*; class GFG { public static void main (String[] args) { //code Scanner sc = new Scanner (System.in); int m =  sc.nextInt();//no of test cases for (int i=0;i<m;i++){    int n =  sc.nextInt(...