Articles on Trending Technologies

Technical articles with clear explanations and examples

C++ program to find the sum of elements between two given indices in array

AYUSH MISHRA
AYUSH MISHRA
Updated on 18-Mar-2025 5K+ Views

Finding the sum of elements between two given indices in an array is a common operation in programming. In C++, there are multiple ways to calculate the sum of elements between two given indices in C++. In this article, we are going to discuss various approaches to calculating the sum of elements between two indices in an array using C++. How to Find the Sum of Elements Between Two Indices? In this problem, we are given an array and two indices, L and R, and we have to find the sum of elements from index L and R (both L ...

Read More

C++ Program to Rotate Array Right by One Position

C++
AYUSH MISHRA
AYUSH MISHRA
Updated on 18-Mar-2025 6K+ Views

Rotating an array means shifting its elements in a specific direction while maintaining their relative order. In this article, we will rotate an array right by one position using C++. For example, if the array is {4, 8, 15, 16, 23}, rotating it right once will result in {23, 4, 8, 15, 16}. We are given an array and need to shift all elements one step to the right, with the last element moving to the first position. Example 1 Input:array = {10, 20, 30, 40, 50} Output:array = {50, 10, ...

Read More

C++ Program to Create Custom Exception

Alshifa Hasnain
Alshifa Hasnain
Updated on 18-Mar-2025 4K+ Views

In this article, we learn to create custom-made, user−defined exceptions in C++. Exceptions are a core concept of C++. They occur when an unwanted or impossible operation occurs during execution. Handling these unwanted or impossible operations is known as exception handling in C++. What is Exception Handling? Exception handling is mainly done using three specific keywords: ' try’, ‘catch’, and ‘throw’. The ‘try’ keyword is used to execute code that may encounter an exception, the ‘catch’ keyword is used to handle such exceptions, and the ‘throws’ keyword is used to create an exception. Exception Types Exceptions in C++ can be divided ...

Read More

Initialize an ArrayList in Java

Alshifa Hasnain
Alshifa Hasnain
Updated on 18-Mar-2025 2K+ Views

In this article, we will learn to initialize an ArrayList in Java. The ArrayList class extends AbstractList and implements the List interface. ArrayList supports dynamic arrays that can grow as needed. Array lists are created with an initial size. When this size is exceeded, the collection is automatically enlarged. When objects are removed, the array may be shrunk. Different Approaches The following are the two different approaches to initialize an ArrayList in Java − Using add() Method Using asList() method Using add() Method One of the most frequent methods of ...

Read More

JavaScript Remove non-duplicate characters from string

Disha Verma
Disha Verma
Updated on 18-Mar-2025 566 Views

Non-duplicate characters in a string are those that appear only once and do not repeat within the string, and the strings are a data type that represents a sequence of characters or text. Sometimes in JavaScript, we need to work with strings and manipulate them based on certain conditions. One of the common tasks is to remove characters that only appear once in a string so that we keep only the characters that appear more than once. In this article, we will understand how to remove non-duplicate characters from a string in JavaScript. Understanding the Problem Suppose we have ...

Read More

Removing all non-alphabetic characters from a string in JavaScript

Disha Verma
Disha Verma
Updated on 18-Mar-2025 1K+ Views

Non-alphabetic characters are any characters that are not part of the alphabet, and the strings are a data type that represents a sequence of characters or text. Working with strings is a basic task in JavaScript, and one common task is removing all non-alphabetic characters from a string. In this article, we will understand how to remove all non-alphabetic characters from a string. Understanding the Problem Suppose we have a string saying "he@656llo wor?ld". We want to remove all digits, punctuation, whitespace, and special characters from the given string. For example: Input string we have: "he@656llo wor?ld" ...

Read More

JavaScript Program to Find Area and Perimeter of Rectangle

Disha Verma
Disha Verma
Updated on 18-Mar-2025 9K+ Views

To find the area and perimeter of a rectangle in JavaScript, we will be using the basic formulas for the perimeter and area of a rectangle. The area of a rectangle is the multiplication of its length by its breadth, and the perimeter of a rectangle is the sum of the lengths of all its four sides. In this article, we are going to understand the formula for the area and perimeter of a rectangle, how to find them using JavaScript, and implement practical examples for this. Understanding the Formulas The formulas for the area and perimeter of a ...

Read More

Can we create a program without a main method in Java?

Alshifa Hasnain
Alshifa Hasnain
Updated on 18-Mar-2025 2K+ Views

Java is a statically typed, object-oriented programming language that needs a main method as an entry point for running. But it is possible to develop Java programs without a main method under certain conditions. Different Approaches The following are the different approaches for creating a program without a main method in Java − Using Static Blocks Using a Servlet Using a JavaFX Application Using Static Blocks (Before Java 7) In previous implementations of Java (prior to Java 7), a program was possible to run with a ...

Read More

How to create an array of integers in JavaScript?

Alshifa Hasnain
Alshifa Hasnain
Updated on 18-Mar-2025 18K+ Views

In this article, we will learn to create an array of integers in JavaScript. The Array parameter is a list of strings or integers. When you specify a single numeric parameter with the Array constructor, you specify the initial length of the array. The maximum length allowed for an array is 4, 294, 967, 295. Different Approaches The following are the two different approaches to creating an array of integers in JavaScript − Using Array Literals Using the Array Constructor Using Array Literals One of the simplest ways to create ...

Read More

C++ Program to Count the Sum of Numbers in a String

C++
AYUSH MISHRA
AYUSH MISHRA
Updated on 18-Mar-2025 65 Views

In this problem, we are given a string containing alphanumeric characters, and the task is to extract all the numbers from the string and compute their sum. The numbers may appear anywhere within the string, and we need to identify them and add them together. In this article, we are going to explore different approaches to solving this problem in C++.Example 1Input: str = "anshu123ayush45anshu"Output: Sum = 174Explanation:The numbers extracted from the string are 123, 45, and 6. Their sum is 123 + 45 + 6 = 174.Example 2Input: str = "1abc2def34ghi56jkl"Output: Sum = 93Explanation:The numbers extracted from the string ...

Read More
Showing 12621–12630 of 61,258 articles
Advertisements