はなく、このです:
import java.io.IOException;
import java.util.Scanner;
public class Ticket {
public static void main(String[] ar) throws IOException {
Scanner keb = new Scanner(System.in);
System.out.println("Enter ticket:");
String ticket = keb.nextLine();
String pattern = "[BbFfEe][0-9]{3}";
if (ticket.matches(pattern)) {
System.out.println("Ticket is VALID.");
} else {
System.out.println("Ticket is INVALID, it must starts with B, b, F, f, E, e characters following by 3 digits.");
}
}
}
続きを読む:
Pattern pattern = Pattern.compile("(?i)[bef]\\d{3}");
if (pattern.matcher(ticket).matches()) {
System.out.println("valid ticket");
} else {
System.out.println("Invalid ticket, ticket must start with B, F or E");
}
質問は何ですか? –
あなたの質問は何ですか? – marstran
正規表現 '[B、F、E、b、f、e] [0-9] {3}' – Blobonat