
Write a java program to count the character ââ?¬Ë?aââ?¬â?¢ typed by the user in a paragraph by implementing thread.

Count characters by implementing thread
import java.util.*;
class CountCharacters {
public static void count(final String str){
Runnable readRun1 = new Runnable() {
public void run() {
try{
Thread.sleep(5000);
String st=str.replaceAll(" ", "");
char ch[]=st.toCharArray();
int count=ch.length;
System.out.println("Total Characters: "+count);
} catch(Exception ex) {
}
}
};
Thread thread1 = new Thread(readRun1);
thread1.start();
}
public static void main(String[] args) throws Exception{
Scanner input=new Scanner(System.in);
System.out.print("Please enter string ");
String str=input.nextLine();
count(str);
}
}
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.