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

I have to write a function( public static int rec(String u,char p)) thattakes a

ID: 3617278 • Letter: I

Question

I have to write a function( public static int rec(String u,char p)) thattakes a string and character and returns the number of occurencesin the string. Heres what i have int blab=0;
int counter=0;
public static int rec(String u,char p)
{if (u.length()==0){return 0;};
if(u.charAt(counter))
{blab++;};
counter++;
if (counter<u.length()){rec(u,p);};
}
I get the error {non staticmethod cannot be referenced from static} I have to write a function( public static int rec(String u,char p)) thattakes a string and character and returns the number of occurencesin the string. Heres what i have int blab=0;
int counter=0;
public static int rec(String u,char p)
{if (u.length()==0){return 0;};
if(u.charAt(counter))
{blab++;};
counter++;
if (counter<u.length()){rec(u,p);};
}
I get the error {non staticmethod cannot be referenced from static} Heres what i have int blab=0;
int counter=0;
public static int rec(String u,char p)
{if (u.length()==0){return 0;};
if(u.charAt(counter))
{blab++;};
counter++;
if (counter<u.length()){rec(u,p);};
}
I get the error {non staticmethod cannot be referenced from static}

Explanation / Answer

staticint counter = 0; public static intrec(String u, char p) { if(u.length()>=counter) { return 0; } return(u.charAt(counter++) == p? 1:0) + rec(u, p); }