我已经解决了我之前的代码问题,现在我希望它通过“Else if”识别它是 4 位及以下还是 6 位及以上。
当我输入字母以在“Else if”中使用 System.out.println 来拒绝它时。
String digit;
String regex;
String regex1;
regex = "[0-9]{5}";
String test;
String validLength = "5";
char one, two, three, four, five; {
System.out.println("In this game, you will have to input 5 digits.");
do {
System.out.println("Please input 5-digits.");
digit = console.next();
test = digit.replaceAll("[a-zA-Z]", "");
if (digit.matches(regex)) {
one = (char) digit.charAt(0);
two = (char) digit.charAt(1);
three = (char) digit.charAt(2);
four = (char) digit.charAt(3);
five = (char) digit.charAt(4);
System.out.println((one + two + three + four + five) / 2);
}