-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPythagoreanTriplet.java
More file actions
33 lines (31 loc) · 982 Bytes
/
PythagoreanTriplet.java
File metadata and controls
33 lines (31 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package Codes;
import java.util.Scanner;
public class PythagoreanTriplet {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int size=sc.nextInt();
int[] array=new int[size];
for (int i=0;i<size;i++){
array[i]=sc.nextInt();
}
int a=0,b=0,c=0;
boolean flag=false;
for (int i=0;i<size;i++){
for (int j=i+1;j<size;j++){
for (int k=j+1;k<size;k++){
a=(int)Math.pow(array[i],2);
b=(int)Math.pow(array[j],2);
c=(int)Math.pow(array[k],2);
if (a==b+c || b==a+c || c==a+b){
System.out.println(a+" "+b+" "+c);
flag=true;
}
// else flag=false;
}
}
}
if (flag)
System.out.println("yes");
else System.out.println("no");
}
}