Sunday, 2 December 2012

Number of spacesand words in the string


import java.io.*;
class Space_count{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s;
int l,i,c=0;
System.out.println("Enter the String");
s=br.readLine();
l=s.length();
for(i=0;i<l;i++)
{
if(s.charAt(i)==' ')
{
c++;
}
}
System.out.println("The number of spaces in the string"+c);
System.out.println("The number of words in the string"+(c+1));
}
}

No comments:

Post a Comment