我无法让我的其余代码具有以下限制
- 它仅由以下字符组成:“R”、“L”和“0”到“9”</li>
- “R”字符必须恰好出现两次
- “L”字符必须只出现一次
- “L”字符必须出现在两个“R”字符之间
- 每个“R”和“L”字符后必须至少有一个“0”到“9”字符
连续出现的“0”到“9”字符不得超过两个
import java.util.Scanner; public class HW04 { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); // Started by naming all the variables String combination; // char R, L; int length; boolean big_R, big_L; System.out.print("Please enter a valid turn dial lock combination : "); combination = stdIn.nextLine(); System.out.println(""); System.out.println(""); length = combination.length(); if (length <= 9 && length >= 6 ) { R = combination.charAt(0); if (R == 'R' ) big_R = true; else System.out.println(combination + " is not a valid turn dial lock combination"); if } else { System.out.println(combination + " is not a valid turn dial lock combination"); } stdIn.close(); } }