翻译下面Java为delphi编译通过的照样给分
第一段:
package xmu;
import java.util.Random;
public class Greedy {
public int[] Greedy(double[][] SampleSet,int k)
{
int RowCount=SampleSet.length;
int i,M[]=new int[k];
int Newi;
for (i=0;i<k;i++) M=-1;
Random rnd = new Random ()
//产生一个随机数,作为N1
M[0]=rnd.nextInt(RowCount)
//选取随机点
double dist[]=new double[RowCount];
for (i=0;i<RowCount;i++) dist=Double.MAX_VALUE;
dist=d(SampleSet,M,M[0],dist);
for (i=1;i<k;i++)
{
Newi=Nexti(dist,M);
M=Newi;
dist=d(SampleSet,M,M,dist);
}
return M;
}
public int Nexti(double dist[],int M[])
{
double j=-1;
int nexti=-1;
for (int i=0;i<dist.length;i++)
{
if (j<dist &&
!xinm(i,M))
{
j=dist;
nexti=i;
}
}
return nexti;
}
public double[] d(double[][] SampleSet,int M[],int Newi,double dist[])
{
int RowCount=SampleSet.length;
for (int i=0;i<RowCount;i++)
{
if (!xinm(i,M))
dist=distXM(SampleSet,i,M,Newi,dist);
}
return dist;
}
public double distXM(double[][] SampleSet,int x,int M[],int Newi,double dist[])
{
double j;
j=distXY(SampleSet[x],SampleSet[Newi]);
if (dist[x]>j)
dist[x]=j;
return dist[x];
}
public double distXY(double x[],double y[])
{
double dist=0;
for(int i=0;i<x.length;i++) dist=dist+(x-y)*(x-y);
dist=Math.sqrt(dist);
return dist;
}
public boolean xinm(int x,int M[])
{
for (int i=0;i<M.length;i++)
{
if (x==M) return true;
}
return false;
}
}