Question: JAVA- This is my code to verify a password. When I run the code, it lets me input a string and it determines if that

JAVA- This is my code to verify a password. When I run the code, it lets me input a string and it determines if that string is an acceptable password, but that isn't what I want. I don't want anything to show when I run. Instead, I want it to output either "string" is valid! or "string" is invalid when it runs a .dat file.

JAVA- This is my code to verify a password. When I run

import java.util.Scanner;

public class Prog5 { public static void main(String[] args) { Scanner reader = new Scanner(System.in);

String password;

password = reader.next(); boolean result = checkPassword(password); //call the checkArguments function and store the result in a variable System.out.println(result); //print the result }

public static boolean checkPassword(String password){ //method to return valid or invalid password. Takes password as input

boolean isDigit = false; //flag to check if there is a digit in the password boolean isLowerca = false; //flag to check if there is a lowercase character in the password boolean isUpperCa = false; //flag to check if there is a uppercase character in the password if(password.length()

for (int i = 0; i

} else if( Character.isLowerCase(password.charAt(i)) ){ // Check if there is a lowercase character in the password string isLowerca = true; } else if( Character.isUpperCase(password.charAt(i)) ){// Check if there is a an uppercase character in the password string isUpperCa = true; } }

if(isDigit && isLowerca && isUpperCa){ //check if all the conditions meet and then return true

return true; }

return false; }

}

Pa. Pa. Pa. Pa. Pa. oral Noral. Hora. alid alid File inl .dat. cution File in2.dat. cution File in dat

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!