Keith MacInnis Keith MacInnis -4 years ago 47
Java Question

Exact Syntax for passing char array (typed out in a method parameter)


I get a illegal start of expression error starting with the

Here is the method being called:

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

Answer Source

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");

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download