This is my code . Some of the test cases are failing . Can you tell me where did I go wrong in my logic ?
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in) ;
int n = scan.nextInt() ;
triplet(n) ;
}
public static void triplet(int n){
int side1 = 0 ;
int side2 = 0 ;
int side3 = 0 ;
if((n&1) == 0){
int x = n/2 ;
side1 = (x*x)-1 ;
side2 = 2*x ;
side3 = (x*x)+1 ;
}
else{
int x = (n-1)/2 ;
side1 = 2*(x+1)*x ;
side2 = (x+1)*(x+1)-(x*x) ;
side3 = (x+1)*(x+1)+(x*x) ;
}
int lhs = (side1*side1)+(side2*side2) ;
int rhs = side3*side3 ;
if(lhs == rhs){
System.out.print(side1+" "+side3) ;
}
else{
System.out.print(-1) ;
}
}
}