'Return number of nodes equal to degree k

Below is the function we'd be required to fill

public Integer numVerticesGtrDegreeK(Integer v, Integer k);

    // PRE: Graph is connected, v is the id of a vertex in the graph

    // POST: returns the number of nodes that are equal to degree k

How would we write the code for it? Thanks :D

Below is what I've tried

public Integer numVerticesGtrDegreeK(Integer v, Integer k) {
    int count = 0;
    while(v != null) {
        if(v == k) {
            count ++;
        }
    }
    return 0; 
}

Not sure if it's right?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source