Count the character in java

Ads
 

Count the character in java

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

View Answers

February 26, 2011 at 1:13 PM

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);
    }
}

Ads









Related Tutorials/Questions & Answers:
Count the character in java
Count the character in java  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
Character count by while loop
Character count by while loop  Write the program to count the number...]) flag=true; } if(!flag){ System.out.println("Character :"+ch+" occurs "+count...]; int count=0; for ( int i=0; i<third.length; i++){ if (ch==third[i
Advertisements
J2ME count character into string
J2ME count character into string  i am new in J2ME, my problem is how to count character into number, i had been research google for almost 2 days... form which allow user to input character user input helloworld then press
count the repeated character in one string
count the repeated character in one string  to find the how character occurrence in one String (for example the string is -java means there is 2...; } if(!flag){ System.out.println("Character :"+ch+" occurs "+count+" times
Character Directions in java
Character Directions in java  java 2,version 1.4 adds a method "getDirectionality();" , what is the use of this method ?   This method returns the Unicode directionality property for the given character. Character
Setting the default Java character encoding?
Setting the default Java character encoding?  Setting the default Java character encoding
Count characters from text file in Java
is a java code that count the occurrence of each character from text file. import...Count characters from text file in Java  At the "Count chracters fro mtext file in Java". I tried to run the code, but the error at the line have
Ask java count
Ask java count  Good morning, I have a case where there are tables... | Java 1 | 10 | | b002 | beginner java | 5 | | b003 | advanced java book | 26 | | b004 | MySQL 1
How to get the unicode of japanese character input in java
How to get the unicode of japanese character input in java  Good Evening sir/madam; I am trying to create an application in java which needs to show the japanese character on frame and need to get the japanese string from
find all unique character in string using java
find all unique character in string using java  example: hello how are you. output should be waryu
Java count vowels
Java count vowels In this section you will learn how to count the number... and then you will get the number of vowels count. Description of code : In this code... will read the string once you enter the string. Then we have taken a count
Java program to generate the total count
Java program to generate the total count  I need a java program which would take a text file as an input and scans through it to generate the output. For Ex. : If the text file contains the following information: There is/are 3
Java get middle character
Java get middle character In this tutorial, you will learn how to get middle character from the word. Here is an example of getting the middle letter of the word entered by the user using Java. If you have a word string 'company
count statement that saves results on a variable in a java bean
count statement that saves results on a variable in a java bean  ... = ""; ResultSet nu = null; SQLStr = "SELECT COUNT(*) AS COS FROM dev.history WHERE previous like 1; "; SQLStr = "SELECT COUNT(PREVIOUS
count statement that saves results on a variable in a java bean
count statement that saves results on a variable in a java bean  ... = ""; ResultSet nu = null; SQLStr = "SELECT COUNT(*) AS COS FROM dev.history WHERE previous like 1; "; SQLStr = "SELECT COUNT(PREVIOUS
how can add new line character into ajax response for java
how can add new line character into ajax response for java   i want..."; url +="?count=" +str...;% String country=request.getParameter("count"); System.out.println("State
Java Remove a character from string
Java Remove a character from string In this tutorial, you will learn how to remove a character from the string. There are several methods for examining... to remove a particular character from the string. In the given example, we have
java program to insert data into a file and count the number of words from the file???????
java program to insert data into a file and count the number of words from the file???????  java program to insert data into a file and count the number of words from the file
how to count words in string using java
how to count words in string using java  how to count words in string...: "); String st=input.nextLine(); int count=0...()){ String token=stk.nextToken(); count
Java I/O Character Streams
Java I/O Character Streams In this section we will discuss the I/O Character... and for this Java provides the Character stream I/O. Character stream I/O... format to and from the local character set. In Java to facilitate
how can add new line character into ajax response for java
how can add new line character into ajax response for java   i want..."; url +="?count=" +str...;% String country=request.getParameter("count"); System.out.println("State
Count number of occurences and print names alphabetically in Java
Count number of occurences and print names alphabetically in Java  I... for the printCount() method for the code to count the number of occurences of each...]+" "; } str = str.toLowerCase(); int count = -1
Java count characters from file
Java count characters from file In this section, you will learn how to count... into character array in order to count the occurrence of each character... read the file and count the occurrence of each character of the content
How to convert entity character to html character
How to convert entity character to html character  Please help me to "convert entity character to html character" in java. If possible please provide source code which take String as input and return as String
Count Active Thread in JAVA
Count Active Thread in JAVA In this tutorial, we are using activeCount() method of thread to count the current active threads. Thread activeCount() : Thread class provides you to check the current active thread by providing
count occourance no of time no between 0 to 9 given by user in java
count occourance no of time no between 0 to 9 given by user in java  import java.io.*; class count_no { public static void main(String args...); }catch(Exception e){} } }   Here is a java
Write a java program that encrypt and decrypt some string by adding or removing 2 on each character.
Write a java program that encrypt and decrypt some string by adding or removing 2 on each character.  Write a java program that encrypt and decrypt some string by adding or removing 2 on each character. Example 1 : Please Enter
count characters
]=='a'){ count++; } } System.out.println("Character...++; } } System.out.println("Character occurs "+count+" times...count characters  i have to print the total number of char 'A' in all
password validation with special character
password validation with special character  how to validate password with special character using java script
Java count frequency of words in the string
Java count frequency of words in the string. In this tutorial, you will learn how to count the occurrence of each word in the given string. String...;; } str = str.toLowerCase(); int count = -1; for (int i = 0; i < str.length
Find out last character of array
Find out last character of array  How we can find out the last character of array in java program

Ads