import java.util.Scanner;
public class Main {
public static void main(String[] args) {
String sentence = "Lorem ipsum dolor sit amet, consectetur ";
// Create a Scanner object to scan words from the sentence
Scanner scanner = new Scanner(sentence);
// Count the number of words
int wordCount = 0;
while (scanner.hasNext()) {
scanner.next(); // Move to the next word
wordCount++;
}
System.out.println("The number of words is " + wordCount + ".");
// Close the scanner to free resources
scanner.close();
}
}