Print the total number of characters in a string

public class CharacterCount {

	public static int printCharacterCount(String str)
	{
            int count = 0;             
            for(int i = 0; i < str.length(); i++) {    
                 if(str.charAt(i) != ' ')    
                   count++;    
		 }        
            return count;
        }
	
	public static void main(String[] args) {    
               String str = "Hello Welcome To Ksamyatam Softwares Coding World";               
               System.out.println("The given string is: " + "\n" + str);       			             
               System.out.println("\n" + "The Total number of characters in Sting : " +              printCharacterCount(str));    
   }    
}
The given string is: 
Hello Welcome To Ksamyatam Softwares Coding World

The Total number of characters in Sting : 43
Scroll to Top