For some reason, when I try to make a sphere in Java by checking the radius of points, it gives me a cube instead of a sphere. Is the problem with my code or my formula?

```
for(double X = 0; X < diameter; X++ )
        {
            //mcspace.logger.info("X = " + Double.toString(X));
            for(double Y = 0; Y < diameter; Y++ )
            {
                //mcspace.logger.info("Y = " + Double.toString(Y));
                for(double Z = 0; Z < diameter; Z++ )
                {
                    //mcspace.logger.info("Z = " + Double.toString(Z));
                    int radius = diameter / 2;

                    double cX = X;
                    double cZ = Z;
                    double cY = Y;

                    if (X > radius){cX -= radius;}
                    if (Y > radius){cY -= radius;}
                    if (Z > radius){cZ -= radius;}

                    double Cr = Math.sqrt(Math.sqrt(Math.pow(cX,2) + Math.pow(cY,2)) + Math.pow(cZ,2));

                    if(Cr <= radius)
                    {
                        SetInShere(X,Y,Z);
                        // This is just a function that is in my code but the problem is that almost all the points are in the sphere, I almost always get a cube instead of a sphere...
                    }
                }
         }
}

```