Java Program to Count Total Character in a String2 min read

In this tutorial, we will see how to Count Total Character in a String in java.

The program below counts the number of letters present in the sentence (String) and displays the total character present in number.

The program checks for spaces present in the Strings and if gets space while checking each character then it will skip the spaces, charAt() function is used in the following java program.

Although if you want to know about the String and loop that are used in the program below. you may click the link below:

We will see two Example:

1. Where the String is already defined in the program.
2. Where the string is taken as an input from the user.


1. Program to Count Total Character in a String in Java

Output:


2. Program to Count Total Character in a String in Java

We will see the example where we will get the String from the user inputs in the program as shown below:

Output:


MORE

C++ Structures

In the C/C++ programming language, the structure is user-defined data types that allow us to store the combination of different data types together. All the …
Read More

C++ Static Keyword

Static s a keyword in C++ that is when used with different types gives different meanings. static keyword can be used with variables in a …
Read More

C++ Templates

Templates in C++ are the powerful feature that allows us to write generic programs (generic classes and generic functions). A single class or function is …
Read More

C++ Friend Function

There are private and protected members in a class that is inaccessible from outside of the class, constituting one of the concepts of object-oriented programming …
Read More

this Pointer in C++

In C++, this is a keyword that refers to the current instance of a class and this pointer holds the address or points to the …
Read More

Inheritance in C++

Inheritance is one of the most important concepts of object-oriented programming. In C++, inheritance is the process of deriving the properties and behaviors of one …
Read More