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]
4 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:
Maslowich4 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
A survey of results on mobile phone datasets analysis
xxMikexx [17]
PErfect! 100% Absolutely beautiful. 
6 0
3 years ago
Which of the following lists the stages of the four-stroke engine cycle in the correct order of operation?
kvasek [131]
The answer is (a) Intake, Compression, Power, Exhaust.
The fourth-stroke engine cycle or the commonly known as the four cycle is a type of engine that completes four separate strokes while turning a crankshaft. First is the Intake where the piston begins at TDC. Second is the compression where it begins at BDC and the piston compresses the air-fuel mixture for ignition. Third is combustion where the second revolution of the cycle starts. Last is the exhaust where the piston once again returns to TDC from BDC.
6 0
3 years ago
What is the value in y2 when the code show below executes?<br> x1 = [ 5 3 1 7 9]; [y1 y2] = min(x1)
horrorfan [7]

Answer:

y2 = 3

Explanation:

This question needs us to give the value of y2 when we run this code in the question.

By min(X1) it is asking for the minimum value in the list of values that we have in the question.

Y1 is the first minimum value in the list and it is = 1

Our answer of interest in this solution is to, which is the second minimum value in the list after Y1

Therefore y2 = 3

Thank you!

3 0
3 years ago
Which team won the first World Series ?
Ulleksa [173]
Boston Red Sox, Boyo
5 0
4 years ago
Read 2 more answers
To rearrange the data on your hard disk so your computer can run more efficiently, you use ____.
Ratling [72]
A disk optimization program, but they're probably looking for defragmenting program.
5 0
3 years ago
Other questions:
  • Andrew has data in cell E14 and the cell should be blank. Andrew should _____.
    15·2 answers
  • What specific type of DNS query instructs a DNS server to process the query until the server replies with an address that satisf
    5·1 answer
  • In cell D5, enter a formula to calculate the number of days for the first workshop. Add 1 to the results to include the total nu
    11·1 answer
  • Which of the following is least likely to be a scientific experiment?
    11·2 answers
  • Help with computer. homework
    15·1 answer
  • You can invoke or call a method from another program or method. When methods must share data, you can pass the data into and ret
    6·1 answer
  • Please help explain this calculator code.
    15·1 answer
  • Pedro needs to write a block of code that will repeat a loop six times. Which type of loop should he use?
    14·2 answers
  • Which term originated on social media?<br> O A. LOL<br> O B. Unlike<br> O C. Notebook<br> D. Word
    7·2 answers
  • Match each item with a statement below.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!