Write Java Program Prompts User Enter Password Matches Specific Pattern Program Must Appro Q37072960

Write a Java program that prompts the user to enter a passwordthat matches a specific pattern. Your program must approve theuser’s entry.. Here is the pattern, in thisorder:

  • 1 or more upper case letters
  • two lower case letters
  • 1 or 2 digits
  • zero or 1 upper case letters
  • any two of this group @#$%^&

Solution


//PatternMatching.java

import java.util.Scanner;
import java.util.regex.*;//Java Regex or Regular Expression is anAPI to define a pattern for searching or manipulatingstrings.
public class Recursion1 {

   public static void main(String[] args) {
      
       Scanner s = new Scanner(System.in);//Scanner object to input password
       System.out.println(“Enter passwrod: “);
       String password = s.next();
       Pattern pattern =Pattern.compile(“[A-Z]+”);  

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.