コードの残りの部分に次の制限を設定するのに問題があります
- 次の文字のみで構成されています:「R」、「L」、および「0」から「9」</li>
- 「R」文字は正確に 2 回出現する必要があります
- 「L」文字は 1 回だけ出現する必要があります
- 「L」文字は、2 つの「R」文字の間に表示する必要があります
- 「R」および「L」の各文字の後には、少なくとも 1 つの「0」から「9」の文字が続く必要があります
「0」から「9」までの文字を連続して 2 つまで使用できます
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(); } }