Can anyone provide an example of how this would be used? (checkExistChar)

edited March 2017 in How To...

Create a boolean method called checkExistChar(char input,char[] array). This method returns true if the given array has the input in one of the indexes (check for duplicates) Otherwise return false

It's used in a hangman game, if that helps.


  • This is obviously an assignment.

    Show us your attempt and we will guide you but we won't do this for you.

  • edited March 2017 Answer ✓
    // can-anyone-provide-an-example-of-how-this-would-be-used-checkexistchar#Item_2
    // GoToLoop (2017-Mar-31)
    @SafeVarargs static final boolean checkExistChar(final char ch, final char... chars) {
      if (chars == null || chars.length == 0)  return false;
      println(new String(chars));
      return java.util.Arrays.binarySearch(chars, ch) >= 0;
    void setup() {
      println(checkExistChar('!', 'S', 'e', 'a', 'r', 'c', 'h', ' ', 'm', 'e', '!'), ENTER);
      println(checkExistChar('à', 'V', 'o', 'i', 'l', 'à'), ENTER);
      println(checkExistChar('ü', 'Ü', 'b', 'e', 'r'));
Sign In or Register to comment.