143. JAVA Program to find number of blank spaces from the given text.
How does this program work?
- This program is used to find number of blank spaces from given text using java.
Here is the code
//To find number of blank spaces from given text
import java.util.Scanner;public class count
{
public static void main(String args[] )
{
int word=1;
String str;
System.out.println("Enter a string" );
Scanner obj =new Scanner(System.in );
str=obj.nextLine();
for(int i=0;i< str.length();++i)
{
if(str.charAt(i)==' ')
word++;
}
System.out.println("Total Blank Spaces="+(word-1) );
}
}