Programming Articles

Page 660 of 2544

How can we check if specific string occurs multiple times in another string in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 3K+ Views

You can find whether a String contains a specified sequence of characters using any of the methods −The indexOf() method − The indexOf() method of the String class accepts a string value and finds the (starting) index of it in the current String and returns it. This method returns -1 if it doesn’t find the given string in the current one.The contains() method − The contains a () method of the String class accepts a sequence of characters value and verifies whether it exists in the current String. If found it returns true else it returns false.In addition to these, you ...

Read More

Linear Search in Python Program

Pavitra
Pavitra
Updated on 11-Mar-2026 15K+ Views

In this article, we will learn about the Linear Search and its implementation in Python 3.x. Or earlier.AlgorithmStart from the leftmost element of given arr[] and one by one compare element x with each element of arr[]If x matches with any of the element, return the index value.If x doesn’t match with any of elements in arr[] , return -1 or element not found.Now let’s see the visual representation of the given approach −Exampledef linearsearch(arr, x):    for i in range(len(arr)):       if arr[i] == x:          return i    return -1 arr = ['t', ...

Read More

Find LCM of rational number in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 209 Views

Here we will see how to find the LCM of Rational numbers. We have a list of rational numbers. Suppose the list is like {2/7, 3/14, 5/3}, then the LCM will be 30/1.To solve this problem, we have to calculate LCM of all numerators, then gcd of all denominators, then the LCM of rational numbers, will be like −$$LCM =\frac{LCM\:of\:all\:𝑛𝑢𝑚𝑒𝑟𝑎𝑡𝑜𝑟𝑠}{GCD\:of\:all\:𝑑𝑒𝑛𝑜𝑚𝑖𝑛𝑎𝑡𝑜𝑟𝑠}$$Example#include #include #include using namespace std; int LCM(int a, int b) {    return (a * b) / (__gcd(a, b)); } int numeratorLCM(vector vect) {    int result = vect[0].first;    for (int i = 1; i < ...

Read More

How to trim white space in StringBuffer in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 3K+ Views

The String class of the java.lang package represents a set of characters. All string literals in Java programs, such as "abc", are implemented as instances of this class. Strings objects are immutable, once you create a String object you cannot change their values, if you try to do so instead of changing the value a new object is created with the required value and the reference shifts to the newly created one leaving the previous object unused.The StringBuffer (and StringBuilder) class is used when there is a necessity to make a lot of modifications to a String.Unlike Strings, objects of ...

Read More

Find nth term of the Dragon Curve Sequence in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 294 Views

Here we will see a program, that can find nth term of the Dragon Curve sequence. The Dragon curve sequence is an infinite binary sequence. It starts with 1, and in each step, it alternatively adds 1s and 0s before and after each element of the previous term, to form the next term.Term 1 : 1Term 2 : 110Term 3 : 1101100Term 4 : 110110011100100We will start with 1, then add 1 and 0, alternatively after each element of the preceding term. When the new term obtained becomes the current term, then repeat the steps from 1 to n to ...

Read More

Find Surpasser Count of each element in array in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 300 Views

Suppose one array A is given. We have to find a number of surpasser of each element in that array. The surpassers are greater elements which are present at the right side of the array of the current element. Suppose A = {2, 7, 5, 3, 0, 8, 1}, the surpassers are {4, 1, 1, 1, 2, 0, 0}, so 2 has 4 numbers at right side, which are greater than 4, and the same rule for others. The solution is very simple, two nested loops will be there, for each element, it will count surpassers, then store them into ...

Read More

BFS using STL for competitive coding in C++?

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 754 Views

The Breadth First Search (BFS) traversal is an algorithm, which is used to visit all of the nodes of a given graph. In this traversal algorithm one node is selected and then all of the adjacent nodes are visited one by one. After completing all of the adjacent vertices, it moves further to check another vertices and checks its adjacent vertices again.In The competitive coding, we have to solve problems very quickly. We will use the STL (Standard Library of C++) to implement this algorithm, we need to use the Queue data structure. All the adjacent vertices are added into ...

Read More

Differences between wait() and join() methods in Java

Nitin Sharma
Nitin Sharma
Updated on 11-Mar-2026 3K+ Views

In multithreading when we deal with threads there comes the requirement of pause and start a thread for this Threading provides two methods wait and join which are used for the same.The following are the important differences between wait() and join().Sr. No.Keywait()join()1Declarationwait() method is defined in Object class and hence the wait() method is declared in java.lang package.join() method, on the other hand, is also defined in java.lang package but in Thread class.2Usagewait() method is primarily used for the inter-thread communication.On the other hand join() is used for adding sequencing between multiple threads, one thread starts execution after first thread ...

Read More

C/C++ Program for Largest Sum Contiguous Subarray?

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 510 Views

An array of integers is given. We have to find sum of all elements which are contiguous. Whose sum is largest, that will be sent as output.Using dynamic programming we will store the maximum sum up to current term. It will help to find sum for contiguous elements in the array.Input: An array of integers. {-2, -3, 4, -1, -2, 1, 5, -3} Output: Maximum Sum of the Subarray is : 7AlgorithmmaxSum(array, n)Input − The main array, the size of the array.Output − maximum sum.Begin    tempMax := array[0]    currentMax = tempMax    for i := 1 to n-1, ...

Read More

Find the other number when LCM and HCF given in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 144 Views

Suppose we have a number A, and LCM and GCD values, we have to find another number B. If A = 5, LCM is 25, HCF = 4, then another number will be 4. We know that −$$𝐴∗𝐵=𝐿𝐶𝑀∗𝐻𝐶𝐹$$$$𝐵= \frac{LCM*HCF}{A}$$Example#include using namespace std; int anotherNumber(int A, int LCM, int GCD) {    return (LCM * GCD) / A; } int main() {    int A = 5, LCM = 25, GCD = 4;    cout

Read More
Showing 6591–6600 of 25,433 articles
« Prev 1 658 659 660 661 662 2544 Next »
Advertisements