Java program to check the no.of occurrences of a given character within the given string
---------------------------------------------------------------------------------------------------------------------------
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner s= new Scanner(System.in);
System.out.print("Enter your String=");
String str=s.nextLine();
System.out.println("Your String="+str);
Scanner r=new Scanner(System.in);
System.out.println("Enter the character you want the occurence of= ");
char c=r.next().charAt(0);
System.out.println();
int occ=0;
for(int i =0;i less than str.length();i++) {
if(str.charAt(i)==c)
occ++;
}
System.out.println("Number of occurence of " +c+ "is= "+occ);
}
}