public class Main {
public static void main(String[] args) {
String sentence = "Lorem ipsum dolor sit amet, consectetur ";
// Remove any trailing punctuation at the end of the sentence
sentence = sentence.replaceAll("[^a-zA-Z0-9]+$", "");
// Split the sentence into an array of words using the split method
String[] words = sentence.split("\\s+");
// Count the number of words
int wordCount = words.length;
System.out.println("The number of words is " + wordCount + ".");
}
}