Write a program to find Number of Word Avilable in givin String
=============================================================
import java.util.Scanner;
class FindNumberOfWordAvilable{
public static void main(String[] args) {
//Take the String Through the user
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
//take the count variable to count number of word int count=0;
//Applay the loop To go through the end of the String for(int i=0;i<s.length();i++){
//Applay the logic to check the Condition
if(((i>0)&&(s.charAt(i)!=' ')&&(s.charAt(i-1)==' '))|| (s.charAt(0)!=' ')&&i==0)
count++;
}
System.out.println("Count:"+count);
}
}
Output
========================================================================
Comments
Post a Comment