我有两节课:
public class node {
static LinkedList<Integer> nodes = new LinkedList<Integer>();
public boolean visited;
public static void Main (String args []) {
System.out.println("Number of nodes in network");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i=1;i<=n;i++){
nodes.add(i);
}
System.out.println(nodes);
}
Run Code Online (Sandbox Code Playgroud)
和另一堂课
public class AdjacencyList {
private int n;
private int density;
Run Code Online (Sandbox Code Playgroud)
我想访问int n的Main方法,并将其值分配给private int n在AdjacencyList类.我尝试node.n(class.variable)格式的方法,我可以分配值,但它没有工作.有人可以帮帮我吗?