You are on page 1of 1

import java.util.

*;
class CountPro
{
public static void main(String[]args)
{
Scanner s = new Scanner(System.in);
String str;
int n,element;
int arr[];
char ch;
System.out.print("Enter a String :: ");
str = s.next();
System.out.print("Enter a character to search :: ");
ch = s.next().charAt(0);
int charcount = count(str,ch);
System.out.print("Enter number of array elements :: ");
n = s.nextInt();
arr = new int[n];
System.out.println("Enter array elements :: ");
for(int i=0;i<arr.length;i++)
arr[i] = s.nextInt();
System.out.print("Enter element to be searched :: ");
element = s.nextInt();
int arraycount = count(arr,element);
}
public static int count(String str,char ch)
{
int count=0;
for(char c:str.toCharArray())
if(c==ch)
count++;
return count;
}
public static int count(int []arr, int p)
{
int count=0;
for(int v:arr)
if(v==p)
count++;
return count;
}
}