
How to count a particular character in a given sentence and also displaying that contain word? Like I want to find "a" in the string "This is example of java Programme" and also display word that contain "a" character.

Here is a java example that accepts a sentence from the user and a character. It then count the occurrence of that character in the string and display the words that contains that character.
import java.util.*;
public class String_Example {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.print("Enter any sentence: ");
String st=input.nextLine();
System.out.print("Enter character: ");
char ch=input.next().charAt(0);
int count=0;
StringTokenizer tokenizer = new StringTokenizer(st);
String s = "";
System.out.println("Words that contains "+ch);
while (tokenizer.hasMoreTokens()) {
s = tokenizer.nextToken();
if (s.contains(Character.toString(ch))){
count++;
System.out.println(s);
}
}
System.out.println(ch+" occurs "+count+" times.");
}
}

thank you
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.