The user inputs any string and the program distinguishes whether the string is qualifying product ID or not.
The qualifying product IDs are any of string consists of two capitals and four numbers. (For example, “TV1523”)
How can I make this program?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You should compare the string using a regular expression, for example:
str.matches("^[A-Z]{2}\\d{4}")will give you a boolean value as to whether it matches or not.The regular expression works as follows:
Using this method, you can loop through any number of strings and check if they match the criteria given.
You should read up on regular expressions though, there are more efficient ways of storing the pattern if you are worried about performance.