# Integer values only from a TABLE output

how can I only show the integers values of this Table data? Like I don't want to see all the other imaginary values displayed even.

Table[Sqrt[(x + y)], {x, -20, 20}, {y, -20, 20}]


Also: You know how the data is displayed in arrays {{},{},{},...{}} which goes through x=-20 with All of y, then x=-19 with all of y again ...etc....x=20 with all of y. Can the actual x and y elements be displayed also (besides the actual final values)?

Thanks, Steve

• Does Flatten[Table[Block[{t = x + y, s}, If[t >= 0, s = Sqrt[t]; If[IntegerQ[s], {{x, y}, s}, Nothing], Nothing]], {x, -20, 20}, {y, -20, 20}], 1] do what you want? – J. M.'s ennui Jan 25 '20 at 23:03
• sol = SortBy[{x, y, s} /. Solve[s == Sqrt[(x + y)] && -20 <= x <= 20 && -20 <= y <= 20, {x, y, s}, Integers], Last] – Bob Hanlon Jan 26 '20 at 0:29
• Nice, wow! this is exactly what I wanted! Thanks so much! But just note seems like the second solution is missing the value for (-19,20) which is actually a 1. But second one skips it. And likely skips a few others too. I wanted to send a screenshot of what I am saying but seems like I cannot attach screenshot to a reply? – Steve237 Jan 26 '20 at 4:48
• Damn, never mind! Apologies, I just saw -19,20 but it was sorted differently and tucked in the middle! Seems like both complete! Thx – Steve237 Jan 26 '20 at 4:54

Try

Table[If[IntegerQ[#], {x, y, #}, Nothing] &[Sqrt[x + y]], {x,  -20,20}, {y,
-20, 20}] // Flatten[#, 1] &

(* {{-20, 20, 0}, {-19, 19, 0}, {-19, 20, 1}, {-18, 18, 0}, {-18, 19,1}
, {-17, 17, 0}, {-17, 18, 1}, {-16, 16, 0}, {-16, 17, 1}, {-16,20, 2}
, {-15, 15, 0}, {-15, 16, 1},...}*)

• Thanks! this looks concise too - by the way I expanded your range from -20 to 20 here. However, now this makes me fully confused when i look at the new outputs, you know why? your new expression now correctly contains all +/- variations of {20, 15, 25} which is totally valid, which is NOT present in the first 2 solutions provided above! however, both their solutions contained +/- variations of {-19, 19, 0}, which is NOT contained in yours! So now all 3 solutions appear incomplete? Please let me know if anyone can see an error anywhere. – Steve237 Jan 26 '20 at 19:48
• I would like to have an ultimate solution which has all values included. Also:can we show a count of all the elements at the end? So I can see a total number of sets? Thanks! – Steve237 Jan 26 '20 at 19:48
• In Addition: Is there a way to bypass the zero elements where x=0 OR y=0? like can the range be split into 2 ranges or exclude those zeros? Since there are many obvious ones there that distort the answer (However good to see both, but 1 more expression to exclude those)? Thx – Steve237 Jan 26 '20 at 19:55
• LOL never mind - you subtly rearranged my original equation to Sqrt[x^2+y^2] whereas the original one was Sqrt[x+y] which is why your answers differed from others. Ok so seems like ALL complete! Thx....P.S. see if you can help with my other question is zero-excludes! OR where the OUTOUT is zero, for instance, if there is a way to exclude either inputs or outputs. – Steve237 Jan 26 '20 at 20:00
• x + y == 0 is probably not interesting either. So If[x != 0 && y != 0 && x + y != 0 && IntegerQ[#], {x, y, #}, Nothing] & – Rohit Namjoshi Jan 27 '20 at 0:09