It is necessary to compare the first character of the сhar array with vowel letters (a, y, o, s, u, u, i, u, e, e).
if (chars[0]=='гласные буквы') so that for any vowel to be true .
There is a sort of vowels in order of increasing charcode-s and save them in an array, then you can use a binary search:
char[] chars = "юла".toCharArray(); char[] letters = { 'а', 'е', 'и', 'о', 'у', 'ы', 'э', 'ю', 'я', 'ё' }; int index = Arrays.binarySearch(letters, chars[0]); System.out.println(index >= 0); If you cannot sort an array of vowels for some reason (or for some reason you cannot use a binary search), you can simply create an array of all vowels and walk through it, comparing each letter with the first letter of the original array (which, by the way, has an index 0, not 1):
public static boolean containsLetter(char[] letters, char c) { for (char letter : letters) { if (letter == c) { return true; } } return false; } And an example of use:
char[] chars = "юла".toCharArray(); char[] letters = { 'а', 'у', 'о', 'ы', 'и', 'э', 'я', 'ю', 'ё', 'е' }; System.out.println(containsLetter(letters, chars[0])); Source: https://ru.stackoverflow.com/questions/655377/
All Articles