Algorithm
This is a classical problem in computational geometry and there are a lot of efficient approaches if you're interested. The longest distance problem (aka. diameter of a polygon) is more interesting though, and will introduce you to a really useful tool in computational geometry: the rotating calipersthe rotating calipers.
Code
It's easy to read, but three improvements can be made:
for (int m=i; m<numOfPoints-1;m++)is indeed an interesting optimization (x2 improvement). It would be more readable to make m go fromi+1tonumOfPoints.- You can avoid computing
Math.sqrt(dx*dx + dy*dy);.dx*dx + dy*dyis enough to compare the distances. When printing the distance, you can useMath.sqrt. - First set
shortestDistancetoDouble.MAX_VALUE, this will avoid you theif (m == 0 && i == 0)case and the resulting duplication: you'll always find a distance shorter than infinity.