Logical Programs

Tower of Hanoi Game in Java

Problem: Write a program to solve the Tower of Hanoi puzzle, which involves moving disks from one peg to another while obeying certain rules. The Tower of Hanoi puzzle is a timeless challenge where players move disks between pegs following strict rules. It’s a captivating game that highlights key concepts like recursion and problem-solving strategies. […]

Tower of Hanoi Game in Java Read More »

Get first and last elements from ArrayList Java

Problem Statement: Write a Java program to get first and last elements from ArrayList. Here’s a Java program that demonstrates how to get the first and last elements from an ArrayList, OUTPUT: First Element: 10Last Element: 50 Explanation: By following these steps, the program effectively retrieves and displays the first and last elements from the

Get first and last elements from ArrayList Java Read More »

Create a PriorityQueue to Manage To-Do list

Problem Statement: Write a Java program to create a PriorityQueue to manage a to-do list with tasks having different priorities. Here’s a Java program that demonstrates how to create a PriorityQueue to manage a to-do list with tasks having different priorities. OUTPUT: Task Completed: [Task 2, Priority: 1]Task Completed: [Task 5, Priority: 2]Task Completed: [Task

Create a PriorityQueue to Manage To-Do list Read More »

Queue Implementation using LinkedList

Problem Statement: Write a Java program to implement a basic queue using LinkedList to enqueue and dequeue elements. Here’s a basic implementation of a queue using a LinkedList in Java to enqueue and dequeue elements. OUTPUT: Queue Size: 3Dequeued Element: 1Dequeued Element: 2Queue Size after Dequeue: 1 Explanation: This basic queue implementation provides the fundamental

Queue Implementation using LinkedList Read More »

Create a Custom LinkedList in Java

Problem Statement: Write a Java program to create a custom LinkedList class with methods to add elements, remove elements, find the length, and reverse the list. Here’s a custom linked list class in Java with methods to add elements, remove elements, find the length, and reverse the list. OUTPUT: Original Linked List:1 -> 2 ->

Create a Custom LinkedList in Java Read More »

Swap two elements in ArrayList

Problem Statement: Write a Java program to swap the positions of two elements in an ArrayList given their indices. Here’s a Java program that demonstrates how to swap the positions of two elements in an ArrayList given their indices. OUTPUT: Original List: [Apple, Banana, Cherry, Date, Fig]List after swapping elements at index 1 and index

Swap two elements in ArrayList Read More »

Find unique string in ArrayList with its frequency

Problem Statement: Write a Java program to create a method that takes an ArrayList of strings and returns a Map with each unique string as the key and its frequency as the value. Here’s a Java program that demonstrates how to create a method that takes an ArrayList of strings and returns a Map with

Find unique string in ArrayList with its frequency Read More »

List Sublist: extracts a sublist from an ArrayList

Problem Statement: Write a Java program that extracts a sublist from an ArrayList, given a start and end index. Here’s a Java program that extracts a sublist from an ArrayList given start and end index. OUTPUT: Original List: [Apple, Banana, Cherry, Date, Fig]Sublist from index 1 to 3: [Banana, Cherry] Explanation: By using the subList()

List Sublist: extracts a sublist from an ArrayList Read More »