Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function that takes a sorted array of integers and counts how many diffe

ID: 3651405 • Letter: W

Question

Write a function that takes a sorted array of integers and counts how many different figures are
for more than once. Example: For input f0, 1, 1, 1; 2; 4; 4; 5; 6; 6g answer is 3, because the three numbers (1.4, 6) appear twice or more.
Write a pre condition loop in your application. Remember to write using / for / after exposure. Note that this is only a request to write a pre condition loop, not to prove that it is correct. The pre condition must nevertheless be correct, ie it should be possible to prove it correct.

Explanation / Answer

Program CountSortedArray.java

===================================================

class CountSortedArray
{
    public static void main(String args[])
    {
        int ar[]={1,1,2,3,4,4,4,5,6,7,7,8,8,8,8,9,10,10,11};
        int c=countar(ar);
        System.out.println("The count is: "+c);
    }
    public static int countar(int a[])
    {
        int i,c=0,j,s=0,b=0;
        for(i=0;i<a.length;i++)
        {
            for(j=i+1;j<a.length;j++)
            {
                if(a[i]==a[j]){s++;b=j;}
            }
            if(s>=1){c++;i=b;s=0;}
        }
        return c;
    }
}

===================================================

Sample output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote