Problem of the Day
Friday, January 30, 2026
Problem:
A String Array is declared and initialized as follows:
String[] words = {"alpha", "beta", "gamma", "delta", "epsilon"};A boolean method check takes a String as a parameter and returns true or false, depending on the structure of the word. Which of the following methods could return the series of values true, false, false, false, false for the series of strings in the Array words?
public static boolean check(String word)
{
String vowels = "aeiou";
return vowels.indexOf(word.substring(0,1)) >= 0 &&
vowels.indexOf(word.substring(word.length() - 1)) >= 0;
}public static boolean check(String word)
{
for (int i = 1; i < word.length(); i++)
{
if (word.substring(i, i + 1).equals(word.substring(i - 1, i)))
return true;
}
return false;
}public static boolean check(String word)
{
for (int i = 1; i < word.length(); i++)
{
if (word.substring(0, 1).equals(word.substring(i, i + 1)))
return true;
}
return false;
}
- I only
- II only
- III only
- I and II only
- I and III only
The correct answer is e. The first method checks to see if the first and last letters in the string are both vowels, which is only true for the word "alpha". The third method checks to see if the first letter appears anywhere else in the word, which is also only true for "alpha".