SlideShare a Scribd company logo
1 of 3
Download to read offline
Write the Java source code necessary to build a solution for EITHER of the following problem:
Program A
(Check password) Some websites impose certain rules for passwords. Write a method that
checks whether a string is a valid password. Suppose the password rules are as follows:
A password must have at least eight characters.
A password consists of only letters and digits.
A password must contain at least two digits.
Write a program that prompts the user to enter a password and displays Valid Password if the
rules are followed or Invalid Password otherwise.
Program B
(Count the letters in a string ) Write a method that counts the number of letters in a string using
the following header:
public static int countLetters(String s)
Write a test program that prompts the user to enter a string and displays the number of letters in
the string , not counting numbers, spaces, or symbols.
Solution
Program A:
import java.util.Scanner;
class PasswordValidity
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
boolean size;
boolean special;
boolean digit;
int count = 0;
System.out.println("Enter password:");
String password = scanner.nextLine();
size = false;
special = false;
digit = false;
int length = password.length();
count=0;
int digitLen=0;
while (count < length) {
char ch = password.charAt(count);
if (length >= 8) {
size = true;
}
if (!Character.isLetterOrDigit(ch)) {
special = true;
}
if (Character.isDigit(ch)) {
digitLen++;
digit = true;
}
count++;
}
if (size && !special && digit && digitLen>=2) {
System.out.println(" Valid Password");
} else {
System.out.println("Invalid Password");
}
}
}
Program B:
import java.util.Scanner;
class LetterCount
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
//String str;
System.out.println("Enter String:");
String str= scanner.nextLine();
int res=countLetters(str);
System.out.println("Count: "+res);
}
public static int countLetters(String s)
{
int length=s.length();
int count=0,c=0;
while(count

More Related Content

Similar to Write the Java source code necessary to build a solution for EITHER .pdf

6: Which of the following statements about creating arrays and initializing t...
6: Which of the following statements about creating arrays and initializing t...6: Which of the following statements about creating arrays and initializing t...
6: Which of the following statements about creating arrays and initializing t...sukeshsuresh189
 
202: When the user clicks a JCheckBox, a(n) occurs.
202: When the user clicks a JCheckBox, a(n) occurs.202: When the user clicks a JCheckBox, a(n) occurs.
202: When the user clicks a JCheckBox, a(n) occurs.sukeshsuresh189
 
3: A(n) ________ enables a program to read data from the user.
3: A(n) ________ enables a program to read data from the user.3: A(n) ________ enables a program to read data from the user.
3: A(n) ________ enables a program to read data from the user.sukeshsuresh189
 
22: The logical relationship between radio buttons is maintained by objects o...
22: The logical relationship between radio buttons is maintained by objects o...22: The logical relationship between radio buttons is maintained by objects o...
22: The logical relationship between radio buttons is maintained by objects o...sukeshsuresh189
 
19: When the user presses Enter in a JTextField, the GUI component generates ...
19: When the user presses Enter in a JTextField, the GUI component generates ...19: When the user presses Enter in a JTextField, the GUI component generates ...
19: When the user presses Enter in a JTextField, the GUI component generates ...sukeshsuresh189
 
5: Every Java application is required to have
5: Every Java application is required to have5: Every Java application is required to have
5: Every Java application is required to havesukeshsuresh189
 
15: Which method call converts the value in variable stringVariable to an int...
15: Which method call converts the value in variable stringVariable to an int...15: Which method call converts the value in variable stringVariable to an int...
15: Which method call converts the value in variable stringVariable to an int...sukeshsuresh189
 
16: Which of the following is the method used to display a dialog box to gath...
16: Which of the following is the method used to display a dialog box to gath...16: Which of the following is the method used to display a dialog box to gath...
16: Which of the following is the method used to display a dialog box to gath...sukeshsuresh189
 
13: What do the following statements do?
13: What do the following statements do?13: What do the following statements do?
13: What do the following statements do?sukeshsuresh189
 
Comp 328 final guide (devry)
Comp 328 final guide (devry)Comp 328 final guide (devry)
Comp 328 final guide (devry)sukeshsuresh189
 
7: Assume the following class declaration.
7: Assume the following class declaration.7: Assume the following class declaration.
7: Assume the following class declaration.sukeshsuresh189
 
8: Which statement below could be used to randomly select a state from an arr...
8: Which statement below could be used to randomly select a state from an arr...8: Which statement below could be used to randomly select a state from an arr...
8: Which statement below could be used to randomly select a state from an arr...sukeshsuresh189
 
11: Which is a correct way to invoke the static method sqrt of the Math class?
11: Which is a correct way to invoke the static method sqrt of the Math class?11: Which is a correct way to invoke the static method sqrt of the Math class?
11: Which is a correct way to invoke the static method sqrt of the Math class?sukeshsuresh189
 
14: Consider the class below:
14: Consider the class below:14: Consider the class below:
14: Consider the class below:sukeshsuresh189
 
18: Which of the following does not generate an event?
18: Which of the following does not generate an event?18: Which of the following does not generate an event?
18: Which of the following does not generate an event?sukeshsuresh189
 
17: provides the basic attributes and behaviors of a window—a title bar at th...
17: provides the basic attributes and behaviors of a window—a title bar at th...17: provides the basic attributes and behaviors of a window—a title bar at th...
17: provides the basic attributes and behaviors of a window—a title bar at th...sukeshsuresh189
 
23: Which layout manager is the default for JPanel?
23: Which layout manager is the default for JPanel?23: Which layout manager is the default for JPanel?
23: Which layout manager is the default for JPanel?sukeshsuresh189
 
1: The .class extension on a file means that the file
1:  The .class extension on a file means that the file1:  The .class extension on a file means that the file
1: The .class extension on a file means that the filesukeshsuresh189
 
4: Which of the following is a Scanner method?
4: Which of the following is a Scanner method?4: Which of the following is a Scanner method?
4: Which of the following is a Scanner method?sukeshsuresh189
 
Comp 328 final guide (devry)
Comp 328 final guide (devry)Comp 328 final guide (devry)
Comp 328 final guide (devry)sukeshsuresh189
 

Similar to Write the Java source code necessary to build a solution for EITHER .pdf (20)

6: Which of the following statements about creating arrays and initializing t...
6: Which of the following statements about creating arrays and initializing t...6: Which of the following statements about creating arrays and initializing t...
6: Which of the following statements about creating arrays and initializing t...
 
202: When the user clicks a JCheckBox, a(n) occurs.
202: When the user clicks a JCheckBox, a(n) occurs.202: When the user clicks a JCheckBox, a(n) occurs.
202: When the user clicks a JCheckBox, a(n) occurs.
 
3: A(n) ________ enables a program to read data from the user.
3: A(n) ________ enables a program to read data from the user.3: A(n) ________ enables a program to read data from the user.
3: A(n) ________ enables a program to read data from the user.
 
22: The logical relationship between radio buttons is maintained by objects o...
22: The logical relationship between radio buttons is maintained by objects o...22: The logical relationship between radio buttons is maintained by objects o...
22: The logical relationship between radio buttons is maintained by objects o...
 
19: When the user presses Enter in a JTextField, the GUI component generates ...
19: When the user presses Enter in a JTextField, the GUI component generates ...19: When the user presses Enter in a JTextField, the GUI component generates ...
19: When the user presses Enter in a JTextField, the GUI component generates ...
 
5: Every Java application is required to have
5: Every Java application is required to have5: Every Java application is required to have
5: Every Java application is required to have
 
15: Which method call converts the value in variable stringVariable to an int...
15: Which method call converts the value in variable stringVariable to an int...15: Which method call converts the value in variable stringVariable to an int...
15: Which method call converts the value in variable stringVariable to an int...
 
16: Which of the following is the method used to display a dialog box to gath...
16: Which of the following is the method used to display a dialog box to gath...16: Which of the following is the method used to display a dialog box to gath...
16: Which of the following is the method used to display a dialog box to gath...
 
13: What do the following statements do?
13: What do the following statements do?13: What do the following statements do?
13: What do the following statements do?
 
Comp 328 final guide (devry)
Comp 328 final guide (devry)Comp 328 final guide (devry)
Comp 328 final guide (devry)
 
7: Assume the following class declaration.
7: Assume the following class declaration.7: Assume the following class declaration.
7: Assume the following class declaration.
 
8: Which statement below could be used to randomly select a state from an arr...
8: Which statement below could be used to randomly select a state from an arr...8: Which statement below could be used to randomly select a state from an arr...
8: Which statement below could be used to randomly select a state from an arr...
 
11: Which is a correct way to invoke the static method sqrt of the Math class?
11: Which is a correct way to invoke the static method sqrt of the Math class?11: Which is a correct way to invoke the static method sqrt of the Math class?
11: Which is a correct way to invoke the static method sqrt of the Math class?
 
14: Consider the class below:
14: Consider the class below:14: Consider the class below:
14: Consider the class below:
 
18: Which of the following does not generate an event?
18: Which of the following does not generate an event?18: Which of the following does not generate an event?
18: Which of the following does not generate an event?
 
17: provides the basic attributes and behaviors of a window—a title bar at th...
17: provides the basic attributes and behaviors of a window—a title bar at th...17: provides the basic attributes and behaviors of a window—a title bar at th...
17: provides the basic attributes and behaviors of a window—a title bar at th...
 
23: Which layout manager is the default for JPanel?
23: Which layout manager is the default for JPanel?23: Which layout manager is the default for JPanel?
23: Which layout manager is the default for JPanel?
 
1: The .class extension on a file means that the file
1:  The .class extension on a file means that the file1:  The .class extension on a file means that the file
1: The .class extension on a file means that the file
 
4: Which of the following is a Scanner method?
4: Which of the following is a Scanner method?4: Which of the following is a Scanner method?
4: Which of the following is a Scanner method?
 
Comp 328 final guide (devry)
Comp 328 final guide (devry)Comp 328 final guide (devry)
Comp 328 final guide (devry)
 

More from wailesalekzydelore94

Can you allow a class to be inherited, but prevent a method from bei.pdf
Can you allow a class to be inherited, but prevent a method from bei.pdfCan you allow a class to be inherited, but prevent a method from bei.pdf
Can you allow a class to be inherited, but prevent a method from bei.pdfwailesalekzydelore94
 
Which type of protein does DNA wrap around so that it can be package.pdf
Which type of protein does DNA wrap around so that it can be package.pdfWhich type of protein does DNA wrap around so that it can be package.pdf
Which type of protein does DNA wrap around so that it can be package.pdfwailesalekzydelore94
 
Why is the death of Socrates important How did it underscore or und.pdf
Why is the death of Socrates important How did it underscore or und.pdfWhy is the death of Socrates important How did it underscore or und.pdf
Why is the death of Socrates important How did it underscore or und.pdfwailesalekzydelore94
 
Which of the following was Darwin unaware ofQuestion 2 options.pdf
Which of the following was Darwin unaware ofQuestion 2 options.pdfWhich of the following was Darwin unaware ofQuestion 2 options.pdf
Which of the following was Darwin unaware ofQuestion 2 options.pdfwailesalekzydelore94
 
When an eye appears bloodshot the vessels that are visible are in wh.pdf
When an eye appears bloodshot the vessels that are visible are in wh.pdfWhen an eye appears bloodshot the vessels that are visible are in wh.pdf
When an eye appears bloodshot the vessels that are visible are in wh.pdfwailesalekzydelore94
 
What is body fatSolutionBody fat is the total fat content in .pdf
What is body fatSolutionBody fat is the total fat content in .pdfWhat is body fatSolutionBody fat is the total fat content in .pdf
What is body fatSolutionBody fat is the total fat content in .pdfwailesalekzydelore94
 
What factors affect the degree of membrane fluidity Explain in deta.pdf
What factors affect the degree of membrane fluidity Explain in deta.pdfWhat factors affect the degree of membrane fluidity Explain in deta.pdf
What factors affect the degree of membrane fluidity Explain in deta.pdfwailesalekzydelore94
 
The probability thatapresident of the United States attends Harvard .pdf
The probability thatapresident of the United States attends Harvard .pdfThe probability thatapresident of the United States attends Harvard .pdf
The probability thatapresident of the United States attends Harvard .pdfwailesalekzydelore94
 
The pentose phosphate cycle has an oxidative and a nonoxidative sect.pdf
The pentose phosphate cycle has an oxidative and a nonoxidative sect.pdfThe pentose phosphate cycle has an oxidative and a nonoxidative sect.pdf
The pentose phosphate cycle has an oxidative and a nonoxidative sect.pdfwailesalekzydelore94
 
Standpoint theory suggests that our understanding of gender-based co.pdf
Standpoint theory suggests that our understanding of gender-based co.pdfStandpoint theory suggests that our understanding of gender-based co.pdf
Standpoint theory suggests that our understanding of gender-based co.pdfwailesalekzydelore94
 
select an engineering articlejournal with ethical senerio and justi.pdf
select an engineering articlejournal with ethical senerio and justi.pdfselect an engineering articlejournal with ethical senerio and justi.pdf
select an engineering articlejournal with ethical senerio and justi.pdfwailesalekzydelore94
 
Que don 20 (1 point) C D You discover a heritable trait that is found.pdf
Que don 20 (1 point) C D You discover a heritable trait that is found.pdfQue don 20 (1 point) C D You discover a heritable trait that is found.pdf
Que don 20 (1 point) C D You discover a heritable trait that is found.pdfwailesalekzydelore94
 
Parthenogenesis has been documented in most vertebrate Classes (e.g. .pdf
Parthenogenesis has been documented in most vertebrate Classes (e.g. .pdfParthenogenesis has been documented in most vertebrate Classes (e.g. .pdf
Parthenogenesis has been documented in most vertebrate Classes (e.g. .pdfwailesalekzydelore94
 
organisms in this domain first produce oxygenSolutionThe three.pdf
organisms in this domain first produce oxygenSolutionThe three.pdforganisms in this domain first produce oxygenSolutionThe three.pdf
organisms in this domain first produce oxygenSolutionThe three.pdfwailesalekzydelore94
 
In the cae below identify the subject matter of the controversy, whe.pdf
In the cae below identify the subject matter of the controversy, whe.pdfIn the cae below identify the subject matter of the controversy, whe.pdf
In the cae below identify the subject matter of the controversy, whe.pdfwailesalekzydelore94
 
Listed below are the major steps in protein synthesis and some event.pdf
Listed below are the major steps in protein synthesis and some event.pdfListed below are the major steps in protein synthesis and some event.pdf
Listed below are the major steps in protein synthesis and some event.pdfwailesalekzydelore94
 
1.What are 2nd messengers Give specific examples. How are they used.pdf
1.What are 2nd messengers Give specific examples. How are they used.pdf1.What are 2nd messengers Give specific examples. How are they used.pdf
1.What are 2nd messengers Give specific examples. How are they used.pdfwailesalekzydelore94
 
In a Pp heterozygous organisms, one of the chromosomes carrying the .pdf
In a Pp heterozygous organisms, one of the chromosomes carrying the .pdfIn a Pp heterozygous organisms, one of the chromosomes carrying the .pdf
In a Pp heterozygous organisms, one of the chromosomes carrying the .pdfwailesalekzydelore94
 
How do vesicles carrying proteins destined for secretion move to the .pdf
How do vesicles carrying proteins destined for secretion move to the .pdfHow do vesicles carrying proteins destined for secretion move to the .pdf
How do vesicles carrying proteins destined for secretion move to the .pdfwailesalekzydelore94
 
Hi everyoneI need to help me in this case studyI want summary in.pdf
Hi everyoneI need to help me in this case studyI want summary in.pdfHi everyoneI need to help me in this case studyI want summary in.pdf
Hi everyoneI need to help me in this case studyI want summary in.pdfwailesalekzydelore94
 

More from wailesalekzydelore94 (20)

Can you allow a class to be inherited, but prevent a method from bei.pdf
Can you allow a class to be inherited, but prevent a method from bei.pdfCan you allow a class to be inherited, but prevent a method from bei.pdf
Can you allow a class to be inherited, but prevent a method from bei.pdf
 
Which type of protein does DNA wrap around so that it can be package.pdf
Which type of protein does DNA wrap around so that it can be package.pdfWhich type of protein does DNA wrap around so that it can be package.pdf
Which type of protein does DNA wrap around so that it can be package.pdf
 
Why is the death of Socrates important How did it underscore or und.pdf
Why is the death of Socrates important How did it underscore or und.pdfWhy is the death of Socrates important How did it underscore or und.pdf
Why is the death of Socrates important How did it underscore or und.pdf
 
Which of the following was Darwin unaware ofQuestion 2 options.pdf
Which of the following was Darwin unaware ofQuestion 2 options.pdfWhich of the following was Darwin unaware ofQuestion 2 options.pdf
Which of the following was Darwin unaware ofQuestion 2 options.pdf
 
When an eye appears bloodshot the vessels that are visible are in wh.pdf
When an eye appears bloodshot the vessels that are visible are in wh.pdfWhen an eye appears bloodshot the vessels that are visible are in wh.pdf
When an eye appears bloodshot the vessels that are visible are in wh.pdf
 
What is body fatSolutionBody fat is the total fat content in .pdf
What is body fatSolutionBody fat is the total fat content in .pdfWhat is body fatSolutionBody fat is the total fat content in .pdf
What is body fatSolutionBody fat is the total fat content in .pdf
 
What factors affect the degree of membrane fluidity Explain in deta.pdf
What factors affect the degree of membrane fluidity Explain in deta.pdfWhat factors affect the degree of membrane fluidity Explain in deta.pdf
What factors affect the degree of membrane fluidity Explain in deta.pdf
 
The probability thatapresident of the United States attends Harvard .pdf
The probability thatapresident of the United States attends Harvard .pdfThe probability thatapresident of the United States attends Harvard .pdf
The probability thatapresident of the United States attends Harvard .pdf
 
The pentose phosphate cycle has an oxidative and a nonoxidative sect.pdf
The pentose phosphate cycle has an oxidative and a nonoxidative sect.pdfThe pentose phosphate cycle has an oxidative and a nonoxidative sect.pdf
The pentose phosphate cycle has an oxidative and a nonoxidative sect.pdf
 
Standpoint theory suggests that our understanding of gender-based co.pdf
Standpoint theory suggests that our understanding of gender-based co.pdfStandpoint theory suggests that our understanding of gender-based co.pdf
Standpoint theory suggests that our understanding of gender-based co.pdf
 
select an engineering articlejournal with ethical senerio and justi.pdf
select an engineering articlejournal with ethical senerio and justi.pdfselect an engineering articlejournal with ethical senerio and justi.pdf
select an engineering articlejournal with ethical senerio and justi.pdf
 
Que don 20 (1 point) C D You discover a heritable trait that is found.pdf
Que don 20 (1 point) C D You discover a heritable trait that is found.pdfQue don 20 (1 point) C D You discover a heritable trait that is found.pdf
Que don 20 (1 point) C D You discover a heritable trait that is found.pdf
 
Parthenogenesis has been documented in most vertebrate Classes (e.g. .pdf
Parthenogenesis has been documented in most vertebrate Classes (e.g. .pdfParthenogenesis has been documented in most vertebrate Classes (e.g. .pdf
Parthenogenesis has been documented in most vertebrate Classes (e.g. .pdf
 
organisms in this domain first produce oxygenSolutionThe three.pdf
organisms in this domain first produce oxygenSolutionThe three.pdforganisms in this domain first produce oxygenSolutionThe three.pdf
organisms in this domain first produce oxygenSolutionThe three.pdf
 
In the cae below identify the subject matter of the controversy, whe.pdf
In the cae below identify the subject matter of the controversy, whe.pdfIn the cae below identify the subject matter of the controversy, whe.pdf
In the cae below identify the subject matter of the controversy, whe.pdf
 
Listed below are the major steps in protein synthesis and some event.pdf
Listed below are the major steps in protein synthesis and some event.pdfListed below are the major steps in protein synthesis and some event.pdf
Listed below are the major steps in protein synthesis and some event.pdf
 
1.What are 2nd messengers Give specific examples. How are they used.pdf
1.What are 2nd messengers Give specific examples. How are they used.pdf1.What are 2nd messengers Give specific examples. How are they used.pdf
1.What are 2nd messengers Give specific examples. How are they used.pdf
 
In a Pp heterozygous organisms, one of the chromosomes carrying the .pdf
In a Pp heterozygous organisms, one of the chromosomes carrying the .pdfIn a Pp heterozygous organisms, one of the chromosomes carrying the .pdf
In a Pp heterozygous organisms, one of the chromosomes carrying the .pdf
 
How do vesicles carrying proteins destined for secretion move to the .pdf
How do vesicles carrying proteins destined for secretion move to the .pdfHow do vesicles carrying proteins destined for secretion move to the .pdf
How do vesicles carrying proteins destined for secretion move to the .pdf
 
Hi everyoneI need to help me in this case studyI want summary in.pdf
Hi everyoneI need to help me in this case studyI want summary in.pdfHi everyoneI need to help me in this case studyI want summary in.pdf
Hi everyoneI need to help me in this case studyI want summary in.pdf
 

Recently uploaded

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 

Recently uploaded (20)

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 

Write the Java source code necessary to build a solution for EITHER .pdf

  • 1. Write the Java source code necessary to build a solution for EITHER of the following problem: Program A (Check password) Some websites impose certain rules for passwords. Write a method that checks whether a string is a valid password. Suppose the password rules are as follows: A password must have at least eight characters. A password consists of only letters and digits. A password must contain at least two digits. Write a program that prompts the user to enter a password and displays Valid Password if the rules are followed or Invalid Password otherwise. Program B (Count the letters in a string ) Write a method that counts the number of letters in a string using the following header: public static int countLetters(String s) Write a test program that prompts the user to enter a string and displays the number of letters in the string , not counting numbers, spaces, or symbols. Solution Program A: import java.util.Scanner; class PasswordValidity { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); boolean size; boolean special; boolean digit; int count = 0; System.out.println("Enter password:"); String password = scanner.nextLine(); size = false; special = false; digit = false; int length = password.length();
  • 2. count=0; int digitLen=0; while (count < length) { char ch = password.charAt(count); if (length >= 8) { size = true; } if (!Character.isLetterOrDigit(ch)) { special = true; } if (Character.isDigit(ch)) { digitLen++; digit = true; } count++; } if (size && !special && digit && digitLen>=2) { System.out.println(" Valid Password"); } else { System.out.println("Invalid Password"); } } } Program B: import java.util.Scanner; class LetterCount { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); //String str; System.out.println("Enter String:"); String str= scanner.nextLine(); int res=countLetters(str); System.out.println("Count: "+res); }
  • 3. public static int countLetters(String s) { int length=s.length(); int count=0,c=0; while(count