15,747,059 members
See more:
Hello guys,
can someone help me with Simple Code?
Example:
a b c d e f g h i j k l m n o p q r s t u v w x y z

Vowel: A, E, I, O, U,

I need main and method.~

If I enter m, the next Vowel is o, so Output is: 2
How can I code this to have the output 2?

Question 2:
Input x and Output is 3 ( the distance from U is 3 and after z, there aren't any vowel)

Question 3:

Input a and Output is 0 (its stay 0 from Vowel because the letter is vowel itself)

Anyone any idea? please use simple code.
Thanks

What I have tried:

Question 2:
public static char closeVowel(char character) {
if(character == 'z' || character == 'Z')
return (char) (value - 25);
if(isVowel(character)) {
return character;
} else {
return closeVowel((char) (value - 1));
}
}

public static boolean isVowel(char character) {
return "aeiouAEIOU".indexOf(character) >= 0;
}

what to write inside main method? I dont wanna use indexof, is there a way to simple code it? for beginner to understand?

Question 3 ( no code yet)
Posted
Updated 3-Jun-20 3:46am

## Solution 1

As you traverse the list you need to save the index of the character you are trying to locate. If they are in alphabetical order then it is easy to start at the correct point. From there you move forward looking for the next vowel. If found then you can calculate the offset from the search character. If not found return some other value. So if you are looking for 'a' in the above list:
The alphabetic position of 'a' (i.e its numeric value relative to the alphabet) is 0.
If the current character is a vowel then the result is offset of 'a' minus offset of the found vowel, which is 0 - 0, or 0.

Write down a few random letters on paper and think how you would calculate the index values.

## Solution 2

We don't do homework here, so I'll give you no code!

Instead, think about how you might do it manually: you would have a list of vowel positions in the alphabet - 0, 4, 8, 14, 20 and a list of letter positions: a == 0, b == 1, and so on.
You then find which pair of vowel positions the given letter sits in: m = 12, to it sites between i == 8 and o == 14
Subtract the first from the letter position, and the letter position from the last and you have the two distances.
The lower of the two distances is the value you are looking for.

Obviously, if you are above the highest vowel (u == 20, given letter is V, W, X, Y, or Z) then you need to check for that (but adding a dummy "6th vowel" at position 999 solves that problem if you think about it.

Try it: do it manually and you'll see what I mean.