1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Montano1993 [528]
3 years ago
12

Write a function named "isValidPassword" that takes in a string and returns 1 if it stores a valid password and 0 otherwise, A v

alid password must contain at least one lowercase letter, one uppercase letter, and at least one nonletter character. Example: if input string is Example: if input string is "Pass_word", function should return "1" "password", function should return "0"
Computers and Technology
1 answer:
Maslowich3 years ago
8 0

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

You might be interested in
I'm programming in javascript, I tryed to put a code like this, but it doesn't work. could someone help me?
VMariaS [17]

Answer:

Your computer does not support this code because you have put spaces in between the code, or maybe that is how you have written the question.

6 0
3 years ago
.9 What is Artificial Intelligence?
Serhud [2]
C because bread is not happy with you
8 0
3 years ago
Question 7 of 25
Vika [28.1K]

Explanation:

the right answer may be A.

5 0
2 years ago
Convert the decimal (base-10) number 20 to binary (base-2)
Salsk061 [2.6K]

Answer:

10100

Explanation:

20 = 10100

because it isssss

7 0
2 years ago
Will Give Brainliest NEED ASAP!!!!!!!!!!!!!!!!!!!!11 Cheri's teacher asked her to write a program using the input() function. Wh
kari74 [83]

Answer:

d

Explanation:

it is an input

4 0
3 years ago
Other questions:
  • You would like to create a graph that shows how much of your total investments are in stocks, savings, and mutual funds. You sho
    5·2 answers
  • What keyboard command opens the Go To dialog box?
    11·2 answers
  • Is it possible to do Agile project in Waterfall methodology?
    11·2 answers
  • Write a program to convert a fraction to a decimal. Have your program ask for the numerator first, then the denominator. Make su
    10·1 answer
  • Do all light bulbs server a practical purpose?
    14·1 answer
  • Lindsey also needs to calcite the commissions earned each month. If the company earns $200,000 or more in a month, the commissio
    5·1 answer
  • What is the output of the following code:
    10·1 answer
  • Create a class called StockTester that has the following fucntionality. a. Create a main method with an ArrayList named dataStoc
    9·1 answer
  • You are testing a printer you just installed, so you use the operator panel on the printer to print a test page. Later, you use
    13·1 answer
  • Maria is conducting a security investigation and has identified a suspect. The suspect is an employee of the organization who ha
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!