The subexpression “[ ]” matches all the characters specified in the braces. Therefore, to move all the upper case letters to the end of a string −Iterate through all the characters in the given string.Match all the upper case letters in the given string using the regular expression "[A-Z]".Concatenate the special characters and the remaining characters to two different strings.Finally, concatenate the special characters string to the other string.Example 1public class RemovingSpecialCharacters { public static void main(String args[]) { String input = "sample B text C with G upper case LM characters in between"; ... Read More
The following regular expression matches all the special characters i.e. all characters except English alphabet spaces and digits."[^a-zA-Z0-9\s+]"To move all the special characters to the end of the given line, match all the special characters using this regex concatenate them to an empty string and concatenate remaining characters to another string finally, concatenate these two strings.Example 1public class RemovingSpecialCharacters { public static void main(String args[]) { String input = "sample # text * with & special@ characters"; String regex = "[^a-zA-Z0-9\s+]"; String specialChars = ""; String inputData ... Read More
The \b meta character in Java regular expressions matches the word boundaries Therefore to find a particular word from the given input text specify the required word within the word boundaries in the regular expressions as −"\brequired word\b";Example 1import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class MachingWordExample1 { public static void main( String args[] ) { //Reading string value Scanner sc = new Scanner(System.in); System.out.println("Enter input string"); String input = sc.next(); //Regular expression to find digits String regex = "\bhello\b"; ... Read More
The java.util.regex.Matcher class represents an engine that performs various match operations. There is no constructor for this class, you can create/obtain an object of this class using the matches() method of the class java.util.regex.Pattern.The usePattern() method of the Matcher class accepts a Pattern object representing a new regex pattern and uses it to find matches.Exampleimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class UsePatternExample { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter input text: "); String input = sc.nextLine(); String regex = "[#%&*]"; ... Read More
Given with the input as angles and the task is to calculate the value of sin(x) and cos(x) corresponding to the given angle and display the resultFor Sin(x)Sin(x) is a trigonometric function which is used to calculate the value of x angle.Formula$$\sin (x) = \displaystyle\sum\limits_{k=0}^\infty \frac{(-1)^{k}}{(2k+1)!}x^{2k+1}$$For Cos(x)Cos(x) is a trigonometric function which is used to calculate the value of x angle.Formula$$\cos (x) = \displaystyle\sum\limits_{k=0}^\infty \frac{(-1)^{k}}{(2k)!}x^{2k}$$Approach used in the below program is as follows −Input the value of x angle for sin(x) and cos(x)Apply the formulas given for sin(x) and cos(x)Print the resultALGORITHMSTART Step 1-> declare function to calculate value of ... Read More
Given with the value of x and y as a positive integer with the value of n for number of decimal places and the task is to generate the division up to n decimal places.ExampleInput-: x = 36, y = 7, n = 5 Output-: 5.14285 Input-: x = 22, y = 7, n = 10 Output-: 3.1428571428Approach used in the below program is as follows −Input the value of a, b and nCheck if b is 0 than division will go upto infinite and if a is 0 than result will be 0 as something divides to 0 is ... Read More
Given with the points (x1, y1, z1), (x2, y2, z2), (x3, y3, z3) and (x4, y4, z4) and the program must check whether the given points are coplanar or not. Points are said to be coplanar is they lie under same plane and if they are under different-2 planes than the points are not coplanar.Given below is an image containing four points and all are under same plane which is xy plane that means points are coplanarGiven below is an image containing four points and all are under different planes which shows points are not coplanarExampleInput-: x1 = 2, y1 ... Read More
Given with a number and the task is to check whether the input number is a lucky number or not and display the result.What is a Lucky NumberLucky number is the number whose each and every digit is different and if at least one digit is repeating than the number will not be considered as a lucky number.ExampleInput-: n = 1234 Output-: it is a lucky number Explanation-: As there is no repeating digit in a number n so it is a lucky number Input-: n = 3434 Output-: it is not a lucky number Explanation-: In the given number ... Read More
Given with an array of amount invested by multiple person and another array containing the time period for which money is invested by corresponding person and the task is to generate the profit sharing ratio.What is Profit Sharing RatioIn a partnership firm, profits and losses are shared between the partners depending upon the capital invested by them in the business. On the basis of that capital investment percentage we calculate the profit sharing ratio which shows the amount of profit which is to be given to each partner of a business.Formula − Partner 1 = capital invested * time period ... Read More
Given with the positive integer value n and the task is to generate the number of odd days till the given year n.ExampleInput-: days = 500 Output-: number of odd days are: 5 Input-: days = 400 Output-: number of odd days are: 0How to calculate the number of odd days in given number of yearsFor calculating the number of odd days the first thing we need to check is whether the given year is a leap year or not because if it’s a leap year than the number of odd days will get changed. If the year is divisible ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP