class TextAnalyzer {
public static int countWords(String text) {
if (text.isEmpty()) {
return 0;
}
String[] words = text.split(" ");
return words.length;
}
public static int countVowels(String text) {
int count = 0;
String vowels = "aeiouAEIOU";
for (int i = 0; i < text.length(); i++) {
char currentChar = text.charAt(i);
if (vowels.indexOf(currentChar) != -1) {
count++;
}
}
return count;
}
public static String reverseText(String text) {
String result = "";
for (int i = text.length() - 1; i >= 0; i--) {
result = result + text.charAt(i);
}
return result;
}
public static String findLongestWord(String text) {
String[] words = text.split(" ");
String longest = "";
for (int i = 0; i < words.length; i++) {
if (words[i].length() > longest.length()) {
longest = words[i];
}
}
return longest;
}
}
public class Main {
public static void main(String[] args) {
String[] texts = {
"Hello World",
"Java Programming Language",
"I like learning Java",
"Today is a beautiful day"
};
int totalWords = 0;
String textWithMostWords = texts[0];
int maxWords = TextAnalyzer.countWords(texts[0]);
for (int i = 0; i < texts.length; i++) {
String currentText = texts[i];
int words = TextAnalyzer.countWords(currentText);
int vowels = TextAnalyzer.countVowels(currentText);
String reversed = TextAnalyzer.reverseText(currentText);
String longest = TextAnalyzer.findLongestWord(currentText);
System.out.println("Text: " + currentText);
System.out.println("Words: " + words);
System.out.println("Vowels: " + vowels);
System.out.println("Reversed: " + reversed);
System.out.println("Longest word: " + longest);
System.out.println("--------------------");
totalWords = totalWords + words;
if (words > maxWords) {
maxWords = words;
textWithMostWords = currentText;
}
}
System.out.println("Text with most words: " + textWithMostWords);
System.out.println("Number of words: " + maxWords);
System.out.println("Total number of words: " + totalWords);
}
}