I'm still a newbie in Java. What I want to do here is to assign the values from the for loop into an array.
Here is a hardcoded example of what I wanted to achieve:
public class Nodes {
private int noOfNodes;
private Points[] points;
Nodes(){
}
Nodes(int noOfNodes){
this.noOfNodes = noOfNodes;
Points[] points = {
new Points("A", 100, 200),
new Points("B", 200, 300),
new Points("C", 300, 400),
new Points("D", 650, 650),
new Points("E", 500 , 600)
};
this.points=points;
}
The code that I'm trying to append the values from the loop:
Points [] points = new Points[this.noOfNodes];
for(int i=0; i<noOfNodes-(noOfNodes-1); i++){
//randomly generate x and y
float max = 1000;
float min = 1;
float range = max - min + 1;
for (int j=0; j<noOfNodes; j++){
String name = Integer.toString(noOfNodes);
float x = (float)(Math.random() * range) + min;
float y = (float)(Math.random() * range) + min;
}
}
this.points=points;
}
I would love to achieve the same output but I'm not getting the values from the for loop array inside points. Any help is appreciated.
Thank you very much.
i<noOfNodes-(noOfNodes-1)this is always1so why have a loop at all?