I have an argument which is of type char. I want to check that this char is lower case, if this is true then I will make a boolean variable equal true, otherwise, make it equal false. I have created an array of chars:
String argumentStr = args[2];
char argument = argumentStr.charAt(0);
boolean acceptArgument;
char[] lowerCaseAlphabet = {'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'};
Then I have tried two different solutions, but each is outside of the scope of my acceptArgument boolean.
First:
for (int i = 0; i < 27; i++) {
if (argument == lowerCaseAlphabet[i]) {
acceptArgument = true;
} else {
acceptArgument = false;
}
}
Second:
for (char letter: lowerCaseAlphabet) {
if (argument == letter) {
acceptArgument = true;
} else {
acceptArgument = false;
}
}
I understand why it won't work, because of the scope of the if statements compared with the acceptArgument boolean. But I don't know how to get around this. Please advise.
break;afteracceptArgument = true;