Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

https://java2blog.com/java-program-count-number-words-string/

 
package org.arpit.java2blog.java8;
 
public class CountNumberOfWordsInStringMain {
 
    public static void main(String[] args) {
        String str = "welcome to java   tutorial on Java2blog";
 
        int count = 1;
 
        for (int i = 0; i < str.length() - 1; i++)
        {
            if ((str.charAt(i) == ' ') && (str.charAt(i + 1) != ' '))
            {
                count++;
            }
        }
        System.out.println("Number of words in a string : " + count);
    }
}
 
Comment

PREVIOUS NEXT
Code Example
Java ::         System.out.println("Welcome to GeeksforGeeks"); 
Java :: set skin minecraft entity player 
Java :: How to center a print statement text? 
Java :: enhanced 4 loop 
Java :: connectionpool in jdbc 
Java :: records java final 
Java :: class generique java 
Java :: how to make jframe full screen 
Java :: output 
Java :: Java headSet(element, booleanValue) 
Java :: plantuml java 
Java :: java secureRandom certain range 
Java :: java += 
Java :: Java/Perl - "sprintf function in java" or "string format" 
Java :: 2 multiples recursion 
Java :: change size bitmapfont 
Java :: at org.apache.spark.sql.errors.QueryCompilationErrors$.failedToFindKafkaDataSourceError(QueryCompilationErrors.scala:1037) 
Java :: java multiple implements 
Java :: java reverse serach 
Java :: Java Finding Extreme Values 
Java :: Bukkit dev paid account 
Java :: venatana emergente con texto java 
Java :: make a string bean spring xml 
Java :: MinimumAndMaximum 
Java :: java program finish event 
Java :: spring converter in initbinder 
Java :: component spring 
Java :: java function 
Java :: how to set current item for spinner android 
Java :: Java find duplicate items 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =