Practice Questions for Java
Practice Questions for Java
Problem Statement
Parents recently had a kid and they are a huge fan of palindromic strings. Now their relatives have
suggested creating a name for their child from both the parent's first names. Now find a way to
create a palindromic name from their parents' name. Take a substring of size at least one from both
of their names and concatenate them which should create a palindrome. If this is possible in any
Input Format
Constraints
• 2<=len(stn)<=100
Output Format
Evaluation Parameters
• Sample Input
maria
mira
• Sample Output
Yes
• Explanation
If you remove the substring, 'ari' from 'maria' and 'ira' from 'mira' then the final string after
Complete the classes using the Specifications given below. Consider default visibility of classes,
Specifications
Task
Class Stocks
• Write a code that checks for the Profit and Loss in the stock rate.
• If the given parameter rate is 80% of the stockRate then return a string "Hope to raise".
• If the given parameter rate is less than 80% of the stockRate then throw StockLowException
• If the given parameter rate is greater than 80% of the stockRate then throw
Sample Input
class definitions:
class Stocks:
float stockRate
visibility : public
method definition:
visibility: public
method definition:
StockHighException(String msg)
visibility: public
method definition:
StockLowException(String msg)
visibility: public
Sample Input:
stock.checkRate(5.0f);
Sample Output
Your task here is to implement a Java code based on the following specifications.
Note that your code should match the specifications in a precise manner.
Consider default visibility of classes, data fields, and methods unless mentioned.
Specifications
class definitions:
class Book:
Data members:
name: String
IFSC: String
author: String
issuedBy: String
available: boolean
class Library:
Method definition:
visibility: public
issueBook(Book details, String name) throws Exception
visibility: public
class InvalidIFSCException:
method definitions:
InvalidIFSCException(String str)
visibility: public
class BookUnavailableException:
method definitions:
BookUnavailableException(String str)
visibility: public
Task
Class Book
Class Library
throw an InvalidIFSCException with the message "IFSC is invalid" if the IFSC code is not
• If the book is available(true) then set available to false, and issuedBy to name after that
Class InvalidIFSCException
• define a parameterized constructor with a String argument to pass the message to the super
class.
Class BookUnavailableException
class.
• define a parameterized constructor with a String argument to pass the message to the super
class.
Sample Input
----------------------------------------------------
Sample Output
Type of Database
MySQL
school
Problem Statement
• name varchar(5)
• class varchar(5)
Your task is to change name varchar size to 25 and make rollno as a primary key.
Problem Statement
Given a string Str and a character C, your task is to remove the first and last occurrence of the
Input Format
Constraints
Output Format
Sample Input
Codedecode
Sample Output
coddecod
Explanation
Your task here is to implement a Java code based on the following specifications. Note that your
code should match the specifications in a precise manner. Consider default visibility of classes, data
visibility: public
method definition:
Task
• insertSpace(String s): Use lambda expression to format a given string, where a space is
NOTE
• Use the Stream API methods for your implementations, else the test-cases might fail.
Sample Input
capgemini
Sample Output
capgemini
NOTE:
• The above Sample Input and Sample Output are only for demonstration purposes and will
be obtained if you implement the main() method with all method calls accordingly.
• Upon implementation of main() method, you can use the RUN CODE button to pass the
Sample Input as input data in the method calls and arrive at the Sample Output.