Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
6 views

Additional Java Problem Solving Questions (2)

The document presents a comprehensive list of additional Java problem-solving questions categorized into ten sections: Basic Math Operations, Loops, Conditional Statements, Arrays, Strings, Recursion, Searching and Sorting, Object-Oriented Programming, Linked Lists, and Stacks and Queues. Each section contains ten unique questions aimed at enhancing programming skills across different concepts. The questions range from basic operations to complex algorithms, providing a diverse set of challenges for learners.

Uploaded by

tamilpandi469
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Additional Java Problem Solving Questions (2)

The document presents a comprehensive list of additional Java problem-solving questions categorized into ten sections: Basic Math Operations, Loops, Conditional Statements, Arrays, Strings, Recursion, Searching and Sorting, Object-Oriented Programming, Linked Lists, and Stacks and Queues. Each section contains ten unique questions aimed at enhancing programming skills across different concepts. The questions range from basic operations to complex algorithms, providing a diverse set of challenges for learners.

Uploaded by

tamilpandi469
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Additional Java Problem-Solving Questions

Here are additional problem-solving questions for each concept, ensuring no repetition from the

previous set:

1. Basic Math Operations

1. Find the sum of the first `n` natural numbers.

2. Calculate the number of trailing zeros in the factorial of a number.

3. Find the sum of all prime numbers up to a given number `n`.

4. Calculate the digital root of a number (repeatedly sum the digits until a single digit is obtained).

5. Convert a given decimal number to its binary representation.

6. Calculate the greatest common divisor (GCD) of an array of numbers.

7. Check if two numbers are coprime (their GCD is 1).

8. Determine if a number can be expressed as a sum of two prime numbers.

9. Find the number of factors of a given number.

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

numbers are user-defined.

3. Find all the numbers between 1 and `n` that are divisible by both 3 and 5.

4. Generate the first `n` terms of the Pascal triangle.

5. Print the first `n` numbers in the Collatz sequence starting from a given number.

6. Display a diamond pattern using stars for a given number of rows.

7. Create a program to find all perfect squares up to a given number `n`.


8. Calculate the sum of the first `n` odd numbers.

9. Display all the prime factors of a given number.

10. Print the alternating sum of the first `n` natural numbers.

3. Conditional Statements

1. Determine if a character is an alphabet, a digit, or a special character.

2. Check if a given time (hours and minutes) is valid or not.

3. Identify the type of triangle (scalene, isosceles, equilateral) based on the given sides.

4. Write a program to simulate a simple calculator (addition, subtraction, multiplication, division).

5. Check if the given day, month, and year form a valid date.

6. Determine if a number is positive, negative, or zero without using comparison operators.

7. Identify if a character is a lowercase or uppercase letter without using built-in functions.

8. Implement a grading system that supports letter grades (A+, A, A-, etc.).

9. Check if the given three points form a straight line.

10. Create a program to determine the quadrant of a point in a 2D plane.

4. Arrays

1. Rotate an array to the left by a given number of positions.

2. Count how many times an element appears in an array.

3. Split an array into two halves and reverse each half separately.

4. Find the intersection of two arrays (common elements).

5. Check if an array is a palindrome.

6. Find the maximum difference between two elements in an array such that the larger element

comes after the smaller one.

7. Merge two unsorted arrays and then sort the resulting array.

8. Find the longest increasing subsequence in an array.


9. Count the number of subarrays with a sum equal to a given number.

10. Determine the most frequently occurring element in an array.

5. Strings

1. Find all substrings of a given string.

2. Determine if two strings are rotations of each other.

3. Find the first non-repeating character in a string.

4. Convert a Roman numeral to an integer.

5. Replace each character in a string with its next character in the alphabet.

6. Find the longest common prefix among an array of strings.

7. Convert a given string to its equivalent ASCII values.

8. Implement a program to check if a given string is a valid number.

9. Reverse the words in a given sentence without reversing the individual words.

10. Find the longest palindrome substring in a given string.

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.

3. Print all permutations of a string with duplicate characters handled.

4. Solve the N-Queens problem for a given board size.

5. Implement a recursive binary search on a sorted array.

6. Generate all possible subsets of a given set.

7. Find the minimum number of coins required for a given amount using recursion.

8. Evaluate a mathematical expression given as a string.

9. Print all combinations of balanced parentheses for a given number `n`.


10. Solve a Sudoku puzzle using recursion and backtracking.

7. Searching and Sorting

1. Implement a ternary search algorithm.

2. Sort an array using the cocktail shaker sort algorithm.

3. Implement counting sort for an array of non-negative integers.

4. Find the majority element in an array (element appearing more than n/2 times).

5. Perform an exponential search on a sorted array.

6. Sort an array using the radix sort algorithm.

7. Find the median of two sorted arrays of the same size.

8. Implement shell sort for an array.

9. Search for an element in a rotated sorted array.

10. Sort a linked list using merge sort.

8. Object-Oriented Programming (OOP)

1. Design a `Shape` class hierarchy including classes like `Square`, `Rectangle`, and `Triangle`

with methods to calculate area and perimeter.

2. Create a `Vehicle` class with subclasses like `Car`, `Bike`, and `Truck`, implementing methods

for fuel efficiency.

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

inheritance and polymorphism.

10. Implement a simple "Employee Management System" with classes for `Employee`, `Manager`,

and `Department`.

9. Linked Lists

1. Swap nodes in pairs in a linked list.

2. Find the intersection point of two linked lists.

3. Flatten a linked list where each node may have a child linked list.

4. Sort a linked list using bubble sort.

5. Reverse nodes in groups of `k` in a linked list.

6. Find the length of a loop in a linked list.

7. Implement a doubly linked list and perform basic operations.

8. Clone a linked list with next and random pointers.

9. Delete the node at the middle of a linked list.

10. Rotate a linked list to the right by `k` places.

10. Stacks and Queues

1. Implement a deque (double-ended queue).

2. Design a program to sort a stack using another stack.

3. Implement a queue using two stacks.

4. Evaluate an infix expression.

5. Implement a stack that supports getMin() in O(1) time.

6. Find the maximum area of a histogram using a stack.

7. Design a circular queue using linked lists.


8. Implement a priority queue using a heap.

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.

You might also like