hi
how i calculate number of space and tab from the string return by readline() method BufferedReader Class

/* This way you can count no of spaces available in a string....*/
import java.util.*;

public class CountSpaces
{
public static void main (String[] args)
{
BufferedReader buff=new BufferedReader(new InputStreamReader(System.in))
System.out.print ("Enter a sentence or phrase: ");
String str=buff.readLine();
int count = 0;
int limit = str.length();
for(int i = 0; i < limit; ++i)
{
    if(Character.isWhitespace(str.charAt(i)))
    {
         ++count;
    }
}
System.out.println("Number of spaces :"+count);
}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.