Write a Program to Find Out No Of Occurrence Of a Character?
package com.java.Softwaretestingblog; public class FoundNoOfOccurance { public static void main(String[] args) { // TODO Auto-generated method stub String s="i am monoj good boy"; char c='o'; int total_size=s.length(); int replace_sie=s.replace("o", "").length(); System.out.println(total_size +"\t"+replace_sie); int count=s.length()-s.replace("o", "").length(); System.out.println("Number of occurances of 'a' is= "+ count); } }
Execution: The output link
Check Also: Find the Smallest Number in An Array
Output:
19 14 Number of occurrence of 'a' is= 5
Leave a Reply