Count total number of characters in given String program
In this article you are going to learn Print duplicate Character in String in Java Those are asked in interview and most used in project concept which is basic program in Java .
How to print Count total number of characters in given String program ?
public class CountCharacters{
public Static Void main(string[] args) {
String str= "Count Total Characters";
int count= 0;
System.out.println("Length of String is " + str.length());
for(int i=0;i<str.length();i++) {
if(str.charAt(i)!=' ' ) {
count++;
}
}
System.out.println("count of characters" + count+);
}
}
Output :
Length of String is :22
Count of characters : 19