title: How to find the degree of a particular vertex in graph?
body: <pre><code>    import java.util.*;
      import java.io.*;
      public class homework{
          static class Graph {
              private LinkedList&lt;Integer&gt; adjLists[];
              private boolean visited[];
              private int V;
  
              // Graph creation
              Graph(int vertices) {
                  V = vertices;
                  adjLists = new LinkedList[vertices];
                  visited = new boolean[vertices];
  
                  for (int i = 0; i &lt; vertices; i++)
                      adjLists[i] = new LinkedList();
              }
  
              // Add edges to the graph
              void addEdge(int vertices, int dest) {
                  adjLists[vertices].add(dest);
              }
  
              // DFS algorithm
              void DFS(int vertex) {
                  visited[vertex] = true;
                  System.out.print(vertex + " ");
  
                  Iterator&lt;Integer&gt; ite = adjLists[vertex].listIterator();
                  while (ite.hasNext()) {
                      int adj = ite.next();
                      if (!visited[adj])
                          DFS(adj);
                  }
              }
              //BFS algorithm
              void BFS(int s) {
                  boolean visited[] = new boolean[V];
                  visited[s] = true;
                  LinkedList&lt;Integer&gt; queue = new LinkedList&lt;&gt;();
                  queue.add(s);
                  while (queue.size() != 0) {
                      s = queue.poll();
                      System.out.println(s + " ");
  
                      Iterator&lt;Integer&gt; i = adjLists[s].listIterator();
                      while (i.hasNext()) {
                          int n = i.next();
                          if (!visited[n]) {
                              visited[n] = true;
                              queue.add(n);
                          }
                      }
                  }
              }
  
              public static void main(String args[]) {
                  Graph g = new Graph(4);
  
                  g.addEdge(0, 1);
                  g.addEdge(0, 2);
                  g.addEdge(1, 2);
                  g.addEdge(2, 0);
                  g.addEdge(2, 3);
                  g.addEdge(3, 3);
  
                  System.out.println("Following is Depth First Traversal");
  
                  g.DFS(2);
  
                  System.out.println("Flowing is BFS");
                  g.BFS(2);
  
                  int degree = findDegree(G, dest);
                  System.out.println(degree);
              }
          }
      }
  </code></pre>
  
  <p>I apologize if I made too many mistakes, but I don't have much experience with java.I have been trying to create a method that <strong>find the degree of the vertex</strong>.My other methods work like a charm at least for a beginner like me.</p>
  
  <pre><code>static int findDegree(Graph G,int dest){
              int degree = 0;
              for(int i = 0; i &lt; G.dest;i++){
                  if(G.dest[i] == 1){
                      degree++;
                  }
                  return degree;
              }
          }
  </code></pre>
  
  <p>I tried like this but getting errors that saying (G cannot be resolved to a variable,dest cannot be resolved to a variable).Is there a way to solve this or should i just change the  <strong><em>findDegree()</em></strong> method. </p>