Respuesta :
Answer:
import java.util.Scanner;
public class ValidatePassword {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner = new Scanner(System.in);
do {
System.out.print("\nEnter Password:");
String password = "";
password = scanner.nextLine();
int upperFound = 0, lowerFound = 0, digitFound = 0;
for (char c : password.toCharArray()) {
if (Character.isUpperCase(c)) {
upperFound++;
} else if (Character.isLowerCase(c)) {
lowerFound++;
} else if (Character.isDigit(c)) {
digitFound++;
}
}
String errorMessage = "";
if (upperFound < 2) {
errorMessage += "\n uppercase letters";
}
if (lowerFound < 2) {
errorMessage += "\n lowercase letters";
}
if (digitFound < 2) {
errorMessage += "\n digits";
}
// System.out.println(errorMessage);
if (errorMessage.length() > 1) {
System.out
.println("The password did not have enough of the following: "
+ errorMessage);
} else {
System.out.println("Valid password");
break;
}
} while (true);
}
}
output:
Enter Password:23testkk
The password did not have enough of the following:
uppercase letters
Enter Password:TESTabc12345
Valid password
In this exercise we have to use the knowledge of computational language in JAVA to describe a code, like this:
The code can be found in the attached image.
To make it easier the code can be found below as:
import java.util.Scanner;
public class ValidatePassword {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner = new Scanner(System.in);
do {
System.out.print("\nEnter Password:");
String password = "";
password = scanner.nextLine();
int upperFound = 0, lowerFound = 0, digitFound = 0;
for (char c : password.toCharArray()) {
if (Character.isUpperCase(c)) {
upperFound++;
} else if (Character.isLowerCase(c)) {
lowerFound++;
} else if (Character.isDigit(c)) {
digitFound++;
}
}
String errorMessage = "";
if (upperFound < 2) {
errorMessage += "\n uppercase letters";
}
if (lowerFound < 2) {
errorMessage += "\n lowercase letters";
}
if (digitFound < 2) {
errorMessage += "\n digits";
}
// System.out.println(errorMessage);
if (errorMessage.length() > 1) {
System.out
println("The password did not have enough of the following: " + errorMessage);
} else {
System.out.println("Valid password");
break;
}
} while (true);
}
}
See more about JAVA at brainly.com/question/2266606
