In this article, we will learn to subtract 40 days from the calendar in Java. Working with dates is a frequent need in programming, and there are multiple methods of doing it in Java. One of the simplest approaches is to use the Calendar class to remove days from a date. Different Approaches The following are the two to subtract 40 days from the calendar in Java − Using the Calendar Class Using the LocalDate Class Using the Calendar Class The first approach utilizes the Calendar class, which is part ... Read More
Artificial Intelligence is a study of agents that act rationally. These agents often implement a search algorithm to find the goal. A search algorithm consists of Goal state - final destination in the task search space - all available states of the problem initial state - the starting point of the problem There are two sets of search algorithms: Uninformed Search, Informed Search Uninformed search This is also commonly known as blind search. In this type of search, no additional information is provided other than ... Read More
In this article, we will learn to generate all rotations of a number in JavaScript. Producing a primary common problem such as all its rotations comprises the creation of all possible permutations of the digits by rotating its digits. Problem Statement The goal is that if we have given a number, we need to generate all possible rotations of its digits. A rotation is defined as moving the first digit to the end of the number. For exampleInput 123 Explanation 123 (original number) 231 (first rotation: move 1 to the ... Read More
In this article, we will learn to map a String list to lowercase and sort in Java. We need to manipulate the elements of a list, such as converting all strings to lowercase and sorting them. This is particularly useful when dealing with user input, file processing, or data normalization. Problem Statement Given a list of strings, we want to convert all strings to lowercase and sort the list in reverse alphabetical order.For Example: Input ["Apple", "banana", "Cherry", "date"] Output ["date", "cherry", "banana", "apple"] Using Streams API The Streams API provides a useful and functional approach to processing ... Read More
In this article, we will learn to display the date and time in uppercase using Java. Working with date and time in Java is a common requirement in various applications, logging, scheduling, or data processing. Different Approaches The following are the two different approaches to display the date and time in uppercase using Java − Using Formatter and Calendar Using DateTimeFormatter Using Formatter and Calendar The Formatter class in Java allows us to format date and time using the %Tc specifier. We can then convert the output to uppercase using ... Read More
The task is to write C++ programs that calculates the sum of the digits of a given number. For example, if the number is 453, the sum of its digits would be 4 + 5 + 3 = 12. To solve this, we will extract each digit from the number and add them together. We will use basic programming concepts such as loops and arithmetic operations to achieve this. In this article, we will show you how to write a C++ program that takes a number as input and sums the digits of that number. Approaches for ... Read More
In this article, we will write a C++ program that implements a Min Heap. A Min Heap is a binary tree where the value of each node is less than or equal to the values of its children. We will explain how to create a Min Heap using arrays and implement operations like insertion and deletion. The article will cover the following topics: What is a Heap? Types of Heap Representing a Heap What is a Min Heap? What ... Read More
In this article, we'll explain the difference between private and protected access specifiers in C++. Access specifiers in C++ control who can access the variables and functions inside a class. Two commonly used specifiers are private and protected. Private members are accessible only within the class, while protected members can be accessed by the class and its derived classes. We'll show how each specifier works in C++, especially with inheritance, using simple examples to make it easy to understand. Private Access Modifier When we declare a class member as private, it means that this member is only accessible within ... Read More
In this article, we will explain the difference between Insertion Sort and Selection Sort. These are two basic sorting algorithms used to arrange numbers in order. We will look at how they work, how fast they are, and when to use each one. By the end, you'll have a clear understanding of the differences between Insertion Sort and Selection Sort. Here's what we'll cover: What is Insertion Sort? What is Selection Sort? Complexity Comparison Key Differences Between Insertion Sort and Selection Sort ... Read More
In C/C++, we usually use the sizeof operator to find the size of an array. However, once an array is passed to a function, its size is lost. So, how can we find the size of an array without using sizeof? For example, consider this array: int arr[] = {1, 2, 3, 4, 5}; Without using sizeof, we can use a loop to count the number of elements in the array. In this article, we'll show you different methods to find the size of an array in C or C++ without using sizeof, with clear and simple examples. ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP