Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 2161 of 3366
91 Views
The java.util.regex.MatcheResult interface provides methods to retrieve the results of a match.You can get an object of this interface using the toMatchResult() method of the Matcher class. This method returns a MatchResult object which represents the match state of the current matcher.The end(int group) method of this interface accepts an integer representing a particular group and returns the offset before the first match occurred in the specified group.Example Live Demoimport java.util.Scanner; import java.util.regex.MatchResult; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main( String args[] ) { String regex = "(.*)(\d+)(.*)"; //Reading input ... Read More
415 Views
This character class \p{javaMirrored} matches upper case letters. This class matches the characters which returns true when passed as a parameter to the isMirrored() method of the java.lang.Character class.Example 1 Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample { public static void main(String args[]) { //Reading String from user System.out.println("Enter a string"); Scanner sc = new Scanner(System.in); String input = sc.nextLine(); //Regular expression String regex = "[\p{javaMirrored}]"; //Compiling the regular expression Pattern pattern = ... Read More
477 Views
This character class \p{javaWhitespace} matches spaces. This class matches the characters which returns true when passed as a parameter to the isWhitespace() method of the java.lang.Character class.Example 1 Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample { public static void main(String args[]) { //Reading String from user System.out.println("Enter a string"); Scanner sc = new Scanner(System.in); String input = sc.nextLine(); //Regular expression String regex = "[\p{javaWhitespace}]"; //Compiling the regular expression Pattern pattern = Pattern.compile(regex); ... Read More
704 Views
This character class \p{javaUpperCase} matches upper case letters. This class matches the characters which returns true when passed as a parameter to the isUpperCase() method of the java.lang.Character class.Example 1 Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample { public static void main(String args[]) { //Reading String from user System.out.println("Enter a string"); Scanner sc = new Scanner(System.in); String input = sc.nextLine(); //Regular expression String regex = "[\p{javaUpperCase}]"; //Compiling the regular expression Pattern pattern = ... Read More
946 Views
IntUnaryOperator represents a functional interface that takes an int value and returns another int value. It is defined in java.util.function package and used as an assignment target for a lambda expression or method reference. It contains one abstract method: applyAsInt(), two default methods: compose(), andThen() and one static method: identity().Syntax@FunctionalInterface public interface IntUnaryOperatorExampleimport java.util.function.IntUnaryOperator; public class IntUnaryOperatorLambdaTest1 { public static void main(String[] args) { IntUnaryOperator getSquare = intValue -> { // lambda expression int result = intValue * intValue; System.out.println("Getting square: "+ result); return result; }; ... Read More
203 Views
In this problem, we are given numbers in the form of an inverted triangle. Our task is to create a program that will find the maximum path sum in an inverted triangle.Inverted triangle form of number is an arrangement when the first row contains n elements, second n-1, and so on.Here, we have to find the maximum sum that can 3 be obtained by adding one element from each row.Let’s take an example to understand the problem −Input −5 1 9 3 6 2Output − 17Explanation − Here, I have found the path from the last row to the ... Read More
386 Views
In this problem, we are given numbers that are in the form of a triangle. Our task is to create a program that will find the maximum path sum in a triangle.The elements are arranged starting from the 1st row with 1 one element and then next rows with an increasing number of elements till there are elements in the nth row.So, the program will find the path that will provide the maximum sum of elements in the triangle. So, we have to find the path that will provide the maximum sum.Let’s take an example to understand the problem −Input ... Read More
305 Views
In this problem, we are given a binary tree with each node containing a value. Our task is to create a program to find the maximum path sum between two leaves of a binary tree.Here, we have to find the path form one leaf node to another leaf node that will provide the maximum sum of values. This maximum sum path can/cannot include the root node.Binary Tree is a tree data structure in which each node can have a maximum of two child nodes. These are called a left child and right child.Example −Let’s take an example to understand the ... Read More
221 Views
Problem statementGiven two arrays of positive integers. Select two sub-arrays of equal size from each array and calculate maximum possible OR sum of the two sub-arrays.ExampleIf arr1[] = {1, 2, 4, 3, 2} andArr2[] = {1, 3, 3, 12, 2} then maximum result is obtained when we create following two subarrays −Subarr1[] = {2, 4, 3} andSubarr2[] = {3, 3, 12}AlgorithmWe can use below formula to gets result −f(a, 1, n) + f(b, 1, n)Example Live Demo#include using namespace std; int getMaximumSum(int *arr1, int *arr2, int n) { int sum1 = 0; int sum2 = 0; for ... Read More
315 Views
In this problem, we are given an array of size n and a number M. Our task is to create a program that will find the maximum number of unique integers in Sub-array of given size.Here, we will have to find the sub-array of size M that has the maximum number of unique elements.Let’s take an example to understand the problem, Input − array = {4, 1, 2, 1 , 4, 3}. M = 4Output − 4Explanation −All possible combinations of sub-arrays of size 4. {4, 1, 2, 1} = 3 unique elements {1, 2, 1, 4} = 3 unique ... Read More