Find Sum of Elements Between Two Given Indices in Array - C++

AYUSH MISHRA
Updated on 18-Mar-2025 19:13:17

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

AYUSH MISHRA
Updated on 18-Mar-2025 19:12:42

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

Create Custom Exception in C++

Alshifa Hasnain
Updated on 18-Mar-2025 17:55:41

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
Updated on 18-Mar-2025 17:55:13

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

Remove Non-Duplicate Characters from String in JavaScript

Disha Verma
Updated on 18-Mar-2025 13:00:28

543 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

Remove All Non-Alphabetic Characters from a String in JavaScript

Disha Verma
Updated on 18-Mar-2025 12:59:47

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

Find Area and Perimeter of Rectangle in JavaScript

Disha Verma
Updated on 18-Mar-2025 12:59:21

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

Create a Program Without a Main Method in Java

Alshifa Hasnain
Updated on 18-Mar-2025 11:15:51

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

Difference Between JavaScript and ECMAScript

Alshifa Hasnain
Updated on 18-Mar-2025 11:15:26

5K+ Views

In this article, we will learn the difference between JavaScript and ECMAScript. JavaScript and ECMAScript are used somewhat interchangeably, but not quite. JavaScript is a general programming language in general use, and ECMAScript is its standard foundation. What is JavaScript? JavaScript was originally called LiveScript, but Netscape renamed it to JavaScript, perhaps due to the hype surrounding Java. JavaScript first appeared in Netscape 2.0 in 1995 under the name LiveScript. The language's general-purpose core has been integrated into Netscape, Internet Explorer, and other web browsers.The norm of scripting languages such as JavaScript is ECMAScript. The following are the features of ... Read More

Create an Array of Integers in JavaScript

Alshifa Hasnain
Updated on 18-Mar-2025 11:14:51

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

Advertisements