Showing posts with label java length(). Show all posts
Showing posts with label java length(). Show all posts

Saturday, August 23, 2008


Java String Length Example

If you want to count the lenght of the string in java then use lenght() method that returns integer value of a string entered by the user. Below is the example that calculate the length of the string :

import java.lang.*;
import java.io.*;

public class Strlen{
public static void main(String[] args) throws IOException{
System.out.println("Count the Lenght of String");
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter String:");
String str = bf.readLine();
int len = str.length();
System.out.println("Length of Text : " + len);
}
}