What wrong in my submission its working fine

Scanner sc = new Scanner(System.in);

	int n = sc.nextInt();
	double x =0;
	double y =0;
	double result =0;
	double sqn = n*n;
	
	if(n%2!=0) {
		
		double sq = sqn/2;
		
		 x = (double) (sq-0.5);
		 y = (double)(sq+0.5);
		
		 result = y*y - x*x;
		 if (result == sqn) {
				System.out.println((int)x+" "+(int)y);
			}else {
				System.out.println("-1");
			}
	}
	else {
		
		
		x = (int) (Math.pow(n/2, 2)-1);
		y = (int) (Math.pow(n/2, 2)+1);
		
		result = y*y - x*x;
		
		if (result == sqn) {
			System.out.println((int)x+" "+(int)y);
		}else {
			System.out.println("-1");
		}
	}
	
	
}

}

Let the given number be n>2.

For n even, n2+((n/2)2–1)2=((n/2)2+1)2.

For n odd, n2+((n2–1)/2)2=((n2+1)/2)2.

i found this formula, pls check it once

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.