2 wrong answer in pythagoras triplets

here is my code i am having 2 out of 5 wrong answer which i am not able to comprehend.

here is my code

import java.util.*;
public class Main {
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int n=in.nextInt();
double a=0;
double b=0;
double check=0;
if(n==0||n==1)
{
System.out.println("-1");
return;

}
if(n%2==0)
{
	a=(n*n/4-1);
	b=(n*n/4+1);
}
else
{
	  int store = 1 * n * n + 1; 
     
   
   a=store / 2 - 1;
   b=store / 2 ;
}
check=b-(int)b;
if(check==0&&isTri(a,b,n))
System.out.println((int)a+" "+(int)b);
else
System.out.println("-1");
}
static int max(double a,double b,int c)
{
	int g,f,h;
	f=(int)a;
	g=(int)b;
	h=c;
	if(f>g&&f>h)
	return f;
	else if(g>f&&g>h)
	return g;
	else
	return h;
}
static boolean isTri(double a,double b,int c)
{
	    if (a + b <= c || a + c <= b || b + c <= a)
   return (false);
   else return true;
}

}

your else part of the code is doing too much computation…i am sharing an easier way your logic of if part seems correct…we have to do similarly for else also

Pythagorean triplet are of form m^2-n^2, 2mn , m^2+n^2…in this ques you are given a value…assume that this value can be of first form or second form(as it is given in the ques that the value is one of the leg of the triangle)…so if the given value say ‘a’ is even then you can equate it to 2mn…mn=a/2…there can be various values of (m,n)…you can take any value of (m,n)… one possible value can be m=a/2 and n=1…else if the given value ‘a’ is odd equate it to m^2-n^2…by factorization m^2-n^2=(m+n)(m-n)…(m+n)(m-n)=a…there could be many values of (m,n)…you can chose any one…(m+n)=a and (m-n)=1 solving these two equations we get m=(a+1)/2 and n=(a-1)/2…as you know the values of m,n rest of the two pythagorean triplets can be found…

okay ill try that and tell you how it goes

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.