No title

0
public class WordCount { public static int countWords(String text) { if (text == null || text.isEmpty()) { return 0; } String[] words = text.split("\\s+"); // Split the string by whitespace characters return words.length; } public static void main(String[] args) { String inputText = "This is a sample sentence for word count."; // Replace this with your input text int wordCount = countWords(inputText); System.out.println("Word count: " + wordCount); } }

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.