Pages

Get numbers of character in a string

Complete source code below will show you, how to get numbers of character that contain in a String. If you compile and execute source code below, you will get numbers of character is equal to 15 not 14. This is because the whitespace in a String also count.

***********************************************************************
COMPLETE SOURCE CODE FOR : GetNumbersOfCharacterInAString.java
***********************************************************************


public class GetNumbersOfCharacterInAString
{
public static void main(String[]args)
{
//Create a String
//You can change to other String that you want
String a="Hello everybody";

//Get numbers of character in created String and store it in int variable
int numbersOfCharacter=a.length();

//Print result
System.out.println("Numbers of character is : "+numbersOfCharacter);
}
}


***********************************************************************
JUST COMPILE AND EXECUTE IT
***********************************************************************
Related Posts Plugin for WordPress, Blogger...