Write an application that prompts the user for a password that contains at least two uppercase letters, at least three lowercase letters, and at least one digit. Continuously reprompt the user until a valid password is entered. Display a message indicating whether the password is valid; if not, display the reason the password is not valid. Save the file as ValidatePassword.java

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

Ver imagen lhmarianateixeira