``````double[][] a= new double;
int i,j;
int [] controller= new int;
Random rand=new Random();

for(i=0; i<5; i++ )
{
for(j=0; j<5; j++)
{

do
{
a[i][j]= rand.nextDouble();
if(a[i][j]>0.0)
controller[j]++;
System.out.println("a[" + i + "][" + j + "] = " +a[i][j]);

}while( controller[j]==3);

}
}
``````

/* I create some random coordinates using this code snippet.Then i need to create a connected graph of these random coordinates.I take some random value r and then compare between the distances of the points,after comparison i join them if distance d < r.I know the logic,i dont know how to code this.Can u please help me in this.
Thank you in advance.

## Recommended Answers

if you know the logic, you should be able to figure out how to code it.
that's the entire point.

what step(s) are you actually struggling with, how did you try to implement it and what is it doing (wrong)?

## All 4 Replies

if you know the logic, you should be able to figure out how to code it.
that's the entire point.

what step(s) are you actually struggling with, how did you try to implement it and what is it doing (wrong)?

I dont know coding much.I am very new to this.I actually dont know how to join two coordinates.using swings/built-in library applet methods or how?

joining coordinates using Swing? what do you think Swing is? it is a framework to create GUI 's in Java, joining those coordinates is (if I understand you right) not Swing related.
just drawing the line between them is. so, let's say you have two hardcoded points in your code, can you draw a line between them on your graph?

compare the distance d between the coordinates suppose (x1,y1) and (x2,y2) are coordinates..For some value r..if Math.power(d,2) <Math.power(r,2)...Then join the coordinates..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.