The F-35 doesn't need a gun...the war in Ukraine is proof.
We have munitions that can kill a moving tank from 30 miles.
Killing a tank with a gun requires the aircraft to overfly the target. Stealth doesn't work against optically aimed AAA.
But ... but its supposed to do CAS too!! Does it carry enough missiles to take out multiple enemy troops multiple times? Asking for a friend.