Write a Java program that prompts the user to enter a password that matches a specific pattern. Your program must approve the user's entry.. Here is the pattern, in this order:
//PatternMatching.java
import java.util.Scanner;
import java.util.regex.*;//Java Regex or Regular Expression is an
API to define a pattern for searching or manipulating
strings.
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]+"); //compiling the Pattern with
the regex(the pattern to be searched within password
Matcher matcher =
pattern.matcher(password); //matcher object to find for
the given pattern(/regex)
if(matcher.find())
//returns
true if the given pattern exists within the string (password)
{
System.out.println("Password Approved");
}
pattern =
Pattern.compile("[a-z]{2}"); //compiling the Pattern
with the regex(the pattern to be searched within password
matcher =
pattern.matcher(password); //matcher object to find for
the given pattern(/regex)
if(matcher.find())
//returns
true if the given pattern exists within the string (password)
{
System.out.println("Password Approved");
}
pattern =
Pattern.compile("[0-9]{1,2}"); //compiling the Pattern
with the regex(the pattern to be searched within password
matcher =
pattern.matcher(password); //matcher object to find for
the given pattern(/regex)
if(matcher.find())
//returns
true if the given pattern exists within the string (password)
{
System.out.println("Password Approved");
}
pattern =
Pattern.compile("[0-9]{1,2}"); //compiling the Pattern
with the regex(the pattern to be searched within password
matcher =
pattern.matcher(password); //matcher object to find for
the given pattern(/regex)
if(matcher.find())
//returns
true if the given pattern exists within the string (password)
{
System.out.println("Password Approved");
}
pattern =
Pattern.compile("[A-Z]?"); //compiling the Pattern with
the regex(the pattern to be searched within password
matcher =
pattern.matcher(password); //matcher object to find for
the given pattern(/regex)
if(matcher.find())
//returns
true if the given pattern exists within the string (password)
{
System.out.println("Password Approved");
}
pattern =
Pattern.compile("[@#$%^&]{2}"); //compiling the
Pattern with the regex(the pattern to be searched within
password
matcher =
pattern.matcher(password); //matcher object to find for
the given pattern(/regex)
if(matcher.find())
//returns
true if the given pattern exists within the string (password)
{
System.out.println("Password Approved");
}
pattern =
Pattern.compile("[A-Z]+[a-z]{2}[\\\\d]{1,2}[A-Z]{0,1}[@#$%^&]{2}");
//compiling the Pattern with the regex(the pattern to be searched
within password
matcher =
pattern.matcher(password); //matcher object to find for
the given pattern(/regex)
if(matcher.find())
//returns
true if the given pattern exists within the string (password)
{
System.out.println("Password Approved");
}
//
System.out.println(Pattern.matches("[A-Z]+",password)); //1 or more
uppercase letters
//
System.out.println(Pattern.matches("[a-z]{2}", password)); //two
lower case letters
//
System.out.println(Pattern.matches("[\\d]{1,2}",password));//1 or 2
digits
//
System.out.println(Pattern.matches("[A-Z]?",password));//zero or 1
upper case letters
//
System.out.println(Pattern.matches("[@#$%^&]{2}",
password));//any two of this group @#$%^&
//
System.out.println(Pattern.matches("[A-Z]+[a-z]{2}[\\d]{1,2}[A-Z]{0,1}[@#$%^&]{2}",password));
if(password.matches("[A-Z]+[a-z]{2}[\\d]{1,2}[A-Z]{0,1}[@#$%^&]{2}"))
{
//if the
password matches all of the above patterns in the same order as
given
System.out.println("Password Approved");
}
/*
* It is not clearly understood if
the question asks to approve the password only when all of the
above pattern matches in the
* exact same order as given. If so
the answer is in the above if{} condition. Rest individual
conditions check have been
* applied has well so as to
understand how pattern matching is working. You can combine the
results to achieve desired results.
*/
}
}
Write a Java program that prompts the user to enter a password that matches a specific...
Please help me with this program in Java: Write a Java program that prompts the user to enter a password that matches a specific pattern. Your program must approve the user's entry.. Here is the pattern, in this order: 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 @#$%^&
NO LOOPS, write a program, in Java, that prompts the user for a hexadecimal string of EXACTLY 4 hex digits, no more, no less, converts the hexadecimal value to its decimal value using string, character parsing, and Math methods learned in this chapter, and then prints the original string and its converted decimal value. NOTE: Hex digits may be in UPPER or lower case.
FOR JAVA: Summary: Write a program to assess password stringency. The solution should be named Password.java. Include these steps: Write an application that provides the criteria for a strong password, and accepts a user's password from an input dialog box. If the entered password is less than six characters, more than 10 characters, or does not contain at least one uppercase letter and one digit, prompt the user to enter again. When the user's entry meets all the password requirements,...
i need know how Write a program that tests whether a string is a valid password. The password rules are: It must have at least eight characters. It must contain letters AND numbers It must contain at least two digits It must contain an underscore (_) Write a program that prompts the user to enter a password and displays the password entered and whether it is valid or invalid.
Introduction to Java programming You will create a secure password. Ask a user to enter first name and last name. (Allow for mixed case) Create a random integer from 10-99. Create the password string that consists of the upper case letter of the last letter of his/her first name, the random number, and the first three letters of his/her last name in lower case. Example someone with the name Rob Lee might have a password that looks like B56lee. Your...
In Java - Write a program that prompts the user to enter two integers and displays their sum. If the input is incorrect, prompt the user again. This means that you will have a try-catch inside a loop.
IN JAVA (Maximum consecutive increasingly ordered sub-string) Write a program that prompts the user to enter a string and displays the maximum consecutive increasingly ordered sub-string. Analyze the time complexity of your program and explain. Here is a sample run: Enter a string: abcabcdgabxy output abcdg Time complexity is O( ). -n must be display between the parenthesis.
please use java Write a program that prompts the user to enter line of text (including whitespace). The program then replaces the following vocals with numbers: a = 1, e = 2, i = 3, o = 4, u = 5 and outputs the result to the console. The program does not consider case, so a = 1, A = 1, e = 2, E = 2, etc. Example: Input: Hello, how are you? Output: H2ll4, h4w 1r2 y45? The...
Write a program that prompts the user to enter a file name and displays the occurrences of each letter in the file. Letters are case-insensitive. Here is a sample run: Enter a filename: Lincoln.txt Number of A’s: 23 Number of B’s: 0 Number of C’s: 12 …… Number of Y’s: 5 Number of Z’s: 7
write a java program that prompts a user to enter two different numbers, divide the first number by second and prints the result