0% found this document useful (0 votes)
2 views3 pages

Java Programs 1

Uploaded by

Nikhil Wankhede
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Java Programs 1

Uploaded by

Nikhil Wankhede
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Q.1. Write a Java program to print the following grid.

Expected Output :

- - - - -
- - - - -
- - - - -
- - - - -

Q.2. Write a Java program to test if an array contains


a specific value.
Sample array : 10,20,30,40,50.
Ask an user to input a no to search : 20
Output : Entered no is found in array.
2nd input : 100
Output : Entered no is not found in array.

Q.3. Write a Java program to find the second largest


element in an array.
Q.4. Write a Java program to remove the duplicate
elements of a given array and return the new length of the
array.

Sample array Input: [20, 20, 30, 40, 50, 50, 50]

Sample output : After removing the duplicate elements


the program should return 4 as the new length of the
array.

Q.5. Write a Java method to check whether a string is a


valid password or not.
Password rules:
A password must have at least six characters.
A password must have at least 1 uppercase and 1
lowercase character.
A password must contain at least two digits.

Test case 1
Input :
Java
Output :
A password must have at least six characters.

Test case 2
Input :
java1rocks12
Output :
A password must have at least 1 uppercase and 1
lowercase character.

Test case 3
Input :
JavaRocks1
Output :
A password must have at least two digits.
Test case 4
Input :
JavaRocks12
Output :
Your password has been created.

Hint:- Create 3 separate boolean methods(static) that will


return true or false based on the logic and conditions,
Put these methods in a separate class and main method in
a separate class and from main method create object and
than call these methods
Take the password from user and based on user’s entered
password display him the appropriate message according
to out test cases.

You might also like