Given (n) , what is the Count of (x,y) pairs that satisfy the equation x^2+y^2 = n^2. Is there any way I can re-write this code just without using nested loop?
int counter=0;
int x=0;
for (int i =(int) n-1; i>=0 ; i--){
if(i == x)
break;
for (int j = 1; j< (int)n ; j++){
if (Math.pow(i,2)+Math.pow(j,2) == Math.pow(n,2)){
counter++;
x = j;
}
}
}
System.out.print(counter);