Answer:
Here is code in java.
import java.util.*;
import java.lang.*;
import java.io.*;
class Solution
{
public static void main (String[] args) throws java.lang.Exception
{
try{
//declare and initialize string variables
String str1="password";
String str2="Pass_word";
//calling function to check valid password
System.out.println("output of password is: "+isValidPassword(str1));
System.out.println("output of Pass_word is: "+isValidPassword(str2));
}catch(Exception ex){
return;}
}
// functionn to check the valid password
public static int isValidPassword(String str)
{
// variables to count the lower,upper and non character
int i, lower_c = 0, upper_c = 0, non_c = 0;
char ch;
for(i=0;i<str.length();i++)
{
ch = str.charAt(i);
if(ch >= 'a' && ch <= 'z')
{//count of lower character
lower_c++;
}
else if(ch >= 'A' && ch <= 'Z')
{
//count of upper character
upper_c++;
}
else
{
//count of non character
non_c++;
}
}
if(lower_c > 0 && upper_c > 0 && non_c > 0) {
return 1;
} else {
return 0;
}
}
}
Explanation:
Declare and initialize two string variables.In the isValidPassword() function, pass the string parameter and then count the lower, upper and non character in the string.If string contains call the three characters then function will return 1 otherwise it will return 0 .
Output:
output of password is: 0
output of Pass_word is: 1