Additional Java Problem Solving Questions (2)
Additional Java Problem Solving Questions (2)
Here are additional problem-solving questions for each concept, ensuring no repetition from the
previous set:
4. Calculate the digital root of a number (repeatedly sum the digits until a single digit is obtained).
10. Calculate the square root of a number using the Babylonian method.
2. Loops
1. Print a hollow square pattern using stars for a given side length.
2. Generate a sequence where each number is the sum of the previous two, but the first two
3. Find all the numbers between 1 and `n` that are divisible by both 3 and 5.
5. Print the first `n` numbers in the Collatz sequence starting from a given number.
10. Print the alternating sum of the first `n` natural numbers.
3. Conditional Statements
3. Identify the type of triangle (scalene, isosceles, equilateral) based on the given sides.
5. Check if the given day, month, and year form a valid date.
8. Implement a grading system that supports letter grades (A+, A, A-, etc.).
4. Arrays
3. Split an array into two halves and reverse each half separately.
6. Find the maximum difference between two elements in an array such that the larger element
7. Merge two unsorted arrays and then sort the resulting array.
5. Strings
5. Replace each character in a string with its next character in the alphabet.
9. Reverse the words in a given sentence without reversing the individual words.
6. Recursion
1. Find the nth number in a sequence where each term is the sum of the previous three terms.
2. Calculate the number of ways to reach the top of a staircase with `n` steps, taking 1 or 2 steps
at a time.
7. Find the minimum number of coins required for a given amount using recursion.
4. Find the majority element in an array (element appearing more than n/2 times).
1. Design a `Shape` class hierarchy including classes like `Square`, `Rectangle`, and `Triangle`
2. Create a `Vehicle` class with subclasses like `Car`, `Bike`, and `Truck`, implementing methods
3. Implement a `Library` system with classes for `Book`, `Member`, and `Loan`.
4. Create a `Zoo` class with an `Animal` interface implemented by various animal classes (e.g.,
`Lion`, `Elephant`).
5. Develop a `Restaurant` management system with classes for `Menu`, `Order`, and `Customer`.
6. Design a simple banking application with classes for `Account`, `SavingsAccount`, and
`CurrentAccount`.
7. Implement a shopping cart system with classes for `Product`, `Cart`, and `Order`.
8. Create a program to simulate an ATM machine using classes.
9. Develop a `MediaLibrary` with classes for `Movie`, `Song`, and `Podcast`, demonstrating
10. Implement a simple "Employee Management System" with classes for `Employee`, `Manager`,
and `Department`.
9. Linked Lists
3. Flatten a linked list where each node may have a child linked list.
9. Find the first negative integer in every window of size `k` in an array.
10. Implement an LRU (Least Recently Used) cache using a linked list and hashing.
These questions provide diverse challenges and cover various Java programming concepts.