Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases DeMYSTiFieD

Authors: Andy Oppel

2nd Edition

0071747990, 978-0071747998

More Books

Students also viewed these Databases questions