Respuesta :
The requirements to make the passwords stronger are as follows:
1. Replace i with !.
2. Replace a with @.
3. Replace m with M.
4. Replace B with 8.
5. Replace o with .
6. Append q*s to the end of the string.
Since it is not mentioned in what language the program should be, I am going to choose Java.
NOTE: Each and every line of code is explained in the comments (in bold) in the program given below:
//Importing the scanner class for taking an input from the user
import java.util.Scanner;
public class Password{
//Main function
public static void main(String []args){
System.out.println("Enter the password:");
//Letting the user to enter his or her password
Scanner scan = new Scanner(System.in);
//Entered password is stored in the String variable named 'password'
String password = scan.nextLine();
//StringBuilder Class is used to generate a new stronger password. It has the helper functions like append for appending the strings to other strings
StringBuilder strongerPasswordBuilder = new StringBuilder();
//For loop is used to iterate through the entered password character-by-character. The inbuilt 'toCharArray' function is used to convert the entered password into an array of characters.
for (char x: password.toCharArray()){
//Switch Statement is used to replace the characters with the ones given in the requirements.
switch (x) {
//Replacing i with !
case 'i':
strongerPasswordBuilder.append("!");
break;
case 'a':
//Replacing a with @
strongerPasswordBuilder.append("@");
break;
case 'm':
//Replacing m with M
strongerPasswordBuilder.append("M");
break;
case 'B':
//Replacing B with 8
strongerPasswordBuilder.append("8");
break;
case 'o':
//Replacing o with .
strongerPasswordBuilder.append(".");
break;
default:
//Default case where the characters are taken as-is
strongerPasswordBuilder.append(String.valueOf(x));
break;
}
}
//Appending 'q*s' to the end of the string
strongerPasswordBuilder.append("q*s");
//Converting the StringBuilder stream to String so as to get the Stronger Password.
String strongerPassword = strongerPasswordBuilder.toString();
//Printing the Stronger Password
System.out.println("The stronger password is: "+strongerPassword);
}
}
Answer:
The answer.
Explanation:
Here is a screenshot of the code that worked for me. However, for this question you will have to do a few slight adjustments.
Change the 1 to an ! and the s and $ to o and .
Hopefully this helps!
