-3
public static boolean isVowel (char c){
    return "A,a,E,e,I,i,O,o,U,u".indexOf(c) != -1;
}

Can u guys explain the whole concept of this code? what does public static boolean isvowel do? what does return do? and what does .indexOf(c) do and mean? and why use a -1 there? thanks for the help

SamT
  • 10,374
  • 2
  • 31
  • 39
  • 1
    You should read up here: http://docs.oracle.com/javase/tutorial/java/javaOO/methods.html. Actually, start at the beginning over here: http://docs.oracle.com/javase/tutorial/java/javaOO/index.html – u3l Mar 09 '14 at 05:09
  • 1
    In addition to the other answers, it's worth noting that passing `','` (comma) will qualify as a vowel according to this function. It would be better to be `"AaEeIiOoUu".indexOf(c) != -1`. – pickypg Mar 09 '14 at 05:13

2 Answers2

0

A character can be automatically casted to a number. It is not necessarily equal to the display value of that character.

So any int-parameter, such as in indexOf(i) can also accept a char. However, unless you know what you are doing, it is likely a mistake.

There is some more information about this in this question.

As far as the -1, that is answered by the JavaDoc of indexOf. It is one of its possible return values.

Community
  • 1
  • 1
aliteralmind
  • 19,847
  • 17
  • 77
  • 108
0

This is checking if the argument to the function is a vowel. .indexOf() returns -1 if the value is not found. So if the value is not found in the list of vowels, it will return -1. -1 != -1 is False so passing a consonant into isVowel() will return False, while passing a vowel will return True.

SS781
  • 2,507
  • 2
  • 14
  • 17