count word in string no matter the delimiter java

Solutions on MaxInterview for count word in string no matter the delimiter java by the best coders in the world

showing results for - "count word in string no matter the delimiter java"
Rafael
16 Feb 2017
1public static void main(String[] args)
2    { 
3        //Scanner object instantiation 
4        Scanner dude = new Scanner(System.in); 
5       
6       //variable declaration 
7       String string1 = ""; 
8       int count = 0; 
9       boolean isWord = false; 
10       
11       
12       //user prompt and input 
13       System.out.println("Enter in your string"); 
14       string1 = dude.nextLine(); 
15       
16       int endOfLine = string1.length()-1; 
17       char ch [] = string1.toCharArray(); 
18       
19       for (int i = 0; i < string1.length(); i++)
20       { 
21           if(Character.isLetter(ch[i]) && i != endOfLine)
22           {//if character is letter and not end of line
23               isWord = true; //it is part of a word 
24           }  
25           if (!Character.isLetter(ch[i]) && isWord)
26           { //if character is not a letter, and previous 
27             //character is a letter i.e. non-letter is 
28             //preceded by character 
29              count++; //add to word count 
30              isWord = false; //get ready to detect new word  
31           }
32           if (Character.isLetter(ch[i]) && i == endOfLine)
33           { //if character is letter 
34             //and at end of line 
35               count++; //add to word count 
36               isWord = false; 
37           }
38           
39       } 
40       System.out.println("There are " +count+ " words");     
41    }
queries leading to this page
count no of words in a string in java without using split functionjava count words in stringcount of the number of words and delimiter without using split and stringtokenizer in javacounting strings javaword count algorithm javahow ot counto words in jhavajava get number of words in a stringcount word in string no matter the delimiter javapublic int array count the amount of words in a sentencecount words in string javajava count words in textcount how many words in a string javahow many words in a string javacount number of words in a stringjava count words in a stringjava method to count number of word in a stringjava count a word in stringcode to count all the words of each length in text javajava number of words in a stringcount words in a string input using splitcount words in stringcount words in java stringcount words in a string javaamount of words in string javahow to count words in javacounts the number of words of all lengths code java program that counts how many words that start with java program that counts how many words that start with ragexjava word countfind out number of words in stringcount words into string with tokenizerfunction that can can recognise number of times we say a sentence in javapublic int array count certain words in a sentencejava how to count words in a stringcount number of words in a string javaword count in javastring split word count in javanumber of words in a string javacount word in string no matter the delimiter java