Let's learn java programming language with easy steps. This Java tutorial provides you complete knowledge about java technology.

Saturday 24 July 2021

Write a Java Program To Count Letters in String

How To Count Letters in String in Java


In the last post, we have discussed how to find character or character position in string in java with simple examples and now here we are going to create a simple example for how to count letters in java string with examples.

So let's start with a useful example for finding the number of letters in a given java String.

The below example gives you a total number of letters count in a given java string i.e (given string is "sun45tt" and letters in this give string is suntt i.e 5).

Java Program to Count Letters in String

class LettersCountInString
{
public static void main(String args[])
{
String str = "sun45tt";
int count = 0; 
for(int i = 0; i<str.length(); i++)
{
if(Character.isLetter(str.charAt(i)))
{
count++;
}
}
System.out.println(count);
}
}

Output: 5

Here we discussed, how to write a java program to count letters in string with a simple example.


Share:

5 comments:

  1. This blog is so cool. I am learning Java Training online. This blogs helps me find out better understanding about salesforce training. Thank you for this blog!

    ReplyDelete
  2. Very good content post. Please continue to post such awesome posts. It was so attractive reading the article and it helped me improve my knowledge as an updated one. Thanks a lot.

    Java Certification Training in Electronic City

    Advance Java Certification Training in Electronic City

    ReplyDelete
  3. This is really a helpful blog I am really impressed with your work, keep it up the good work
    1Z0-900: Java EE 7 Application Developer

    ReplyDelete
  4. This is really a helpful blog I am really impressed with your work, keep it up the good work
    1Z0-900: Java EE 7 Application Developer

    ReplyDelete
  5. This Article is amazing. I am learning Java Training online from Fullstack Guru. This blog helps me find out a better understanding of Java Concepts. Thank you!

    ReplyDelete

Facebook Page Likes

Follow javatutorial95 on twitter

Popular Posts

Translate