Sail E0 Webinar
Question
Choose the appropriate code that counts the number of non-zero(non-null) elements in the sparse array.
Options:
A .  public int count(){        int count = 0;        for (List cur = this.next; (cur != null); cur = cur.next)        {            count++;        }        return count;}
B .  public int count(){        int count = 0;        for (List cur = this; (cur != null); cur = cur.next)        {            count++;        }        return count;}
C .  public int count(){        int count = 1;        for (List cur = this.next; (cur != null); cur = cur.next)        {            count++;        }        return count;}
D .  None of the mentioned
Answer: Option A


A simple 'for loop' to count the non-null elements.



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers