-1

doPrompt({'a','t','q'},"Test");

I get a illegal start of expression error starting with the { character.

Here is the method being called:

public static char doPrompt(char[] validCharacterValues, String prompt) {
    do {
        System.out.print(prompt);
        Scanner keyboardMonster = new Scanner(System.in);
        String usersInput = keyboardMonster.nextLine().toLowerCase();
        if (arrayContains(validCharacterValues,usersInput.charAt(0)))
            return usersInput.charAt(0);
    } while (true);
}
1

2 Answers 2

1

Arrays can be created inline with new type[]{} with type being the type of the array. So for your case, it would be doPrompt(new char[]{'a','t','q'},"Test");

Sign up to request clarification or add additional context in comments.

Comments

1

You should pass it like this:

doPrompt(new char[]{'t', 'j', 'k'}, "Test");

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.