Your approach is to try every possible $x$ and $y$ and see if $x^2+y^2=n^2$. However, $n$ is fixed and, for any $x$, either $n^2-x^2$ is a perfect square or it isn't. You can calculate what $y$ is, instead of looping and trying every possible value.
Actual code is off-topic but it's confusing that you're trying to solve a problem about $x$ and $y$, but you've represented those quantities in variables called
j. And even worse that you have a variable called
x that represents something else entirely. (In fact, I'm not sure it's even correct. You seem to be using
x to avoid reporting, e.g., $x=3$, $y=4$ and $x=4$, $y=3$ as separate solutions for $n=5$. But they are separate solutions and the question, at least as you've summarized it, doesn't say that they should be counted as the same.)