private boolean nextCharIsDigit(Scanner in) {
return in.hasNext("[0-9]");
}
private char nextChar(Scanner in) {
return in.next().charAt(0);
}
private boolean nextCharIsLetter(Scanner in) {
return in.hasNext("[a-zA-Z]");
}
private boolean nextCharIs(Scanner in, char c) {
return in.hasNext(Pattern.quote(c+""));
}
What im doing is:
Scanner in = new Scanner (System.in);
if(nextCharIsLetter(in)) {
do something
}
The problem im getting is that it only works when the input is 1 letter. So it will work if i input "a" or "g" but as soon there are more characters it goes into the "else". How can i check if the first position is a letter and the following positions a number or letter.


Sign In
Create Account


Back to top









