-1

This is my node class:

public class Node 
{
    public int label;
    public boolean visited=false;
    public Node(int one)
    {
        this.label=one;
    }
}

This is what I'm trying to do but it's giving me an error:

for(int n=0;n<=Nodes;n++)
{
    Node name+n = new Node(n);
}

Cannot convert node to int. Is there any other way I can generate 4 different named nodes? This is a adjacency matrix to graph. Thanks!!!

sashkello
  • 17,306
  • 24
  • 81
  • 109

1 Answers1

4

The reason that it is giving an error is because you have a special character in an identifier. You could create an array of nodes and then use it as follows:

Node[] nodes = new Nodes[4]
for (int n=0; n < 4; n++) {
    nodes[n] = new Node(n);
}

Then you just need to reference the index in the nodes array to call them.

ucsunil
  • 7,378
  • 1
  • 27
  • 32