Phone Number Validation Using Java Regular Expressions

Jai Janardhan
Updated on 30-Jul-2019 22:30:24

3K+ Views

The phone number can be validated using the java.util.regex.Pattern.matches() method. This method matches the regular expression for the phone number and the given input phone number and returns true if they match and false otherwise.Note: We are considering a demo number for our example since we cannot use our phone number publicly.A program that demonstrates this is given as follows:Example Live Demopublic class Demo {    public static void main(String args[]) {       String phoneNumber = "9999999998";       String regex = "(0/91)?[7-9][0-9]{9}";       System.out.println("The phone number is: " + phoneNumber);       System.out.println("Is the ... Read More

Fill Elements in a Java Double Array in a Specified Range

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

324 Views

Elements can be filled in a Java double array in a specified range using the java.util.Arrays.fill() method. This method assigns the required double value in the specified range to the double array in Java.The parameters required for the Arrays.fill() method are the array name, the index of the first element to be filled(inclusive), the index of the last element to be filled(exclusive) and the value that is to be stored in the array elements.A program that demonstrates this is given as follows −Example Live Demoimport java.util.Arrays; public class Demo { public static void main(String[] argv) throws Exception { ... Read More

Zip Code Validation Using Java Regular Expressions

Arushi
Updated on 30-Jul-2019 22:30:24

2K+ Views

The zip code can be validated using the java.util.regex.Pattern.matches() method. This method matches the regular expression for the zip code and the given input zip code and returns true if they match and false otherwise.A program that demonstrates this is given as follows:Example Live Demopublic class Demo {    public static void main(String args[]) {       String zipCode = "83592-1537";       String regex = "\d{5}(-\d{4})?";       System.out.println("The zip code is: " + zipCode);       System.out.println("Is the above zip code valid? " + zipCode.matches(regex));    } }OutputThe zip code is: 83592-1537 Is the above ... Read More

Negative Binary Numbers

Arjun Thakur
Updated on 30-Jul-2019 22:30:24

17K+ Views

Negative numbers can be distinguishable with the help of extra bit or flag called sign bit or sign flag in Binary number representation system for signed numbers. It is not possible to add minus or plus symbol in front of a binary number because a binary number can have only two symbol either 0 or 1 for each position or bit. That’s why we use this extra bit called sign bit or sign flag. The value of sign bit is 1 for negative binary numbers and 0 for positive numbers.When an integer binary number is positive, the sign is represented ... Read More

Why NOT NULL Shouldn’t Be Added to Primary Key Field in MySQL

Chandu yadav
Updated on 30-Jul-2019 22:30:24

844 Views

You do not need to add NOT NULL to primary key field because it gets NOT NULL automatically. Primary key is combination of both NOT NULL and Unique Key.Here is the demo of primary key field. Let us first create a table. The query to create a table is as follows:mysql> create table NotNullAddDemo    -> (    -> Id int AUTO_INCREMENT,    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.81 sec)In the above table, you do not need to add NOT NULL to primary key field because MySQL internally converts it into NOT NULL. To ... Read More

Get Last 5 Characters of a String with MySQL Query

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:24

20K+ Views

To get the first n characters of string with MySQL, use LEFT(). To get the last n char of string, the RIGHT() method is used in MySQL.The syntax for RIGHT() method is as follows −SELECT RIGHT(yourColumnName, valueOfN) as anyVariableName from yourTableName;To understand the above concept, let us create a table. The query to create a table is as follows −mysql> create table gettingLast5Characters    −> (    −> BookName varchar(100)    −> ); Query OK, 0 rows affected (0.73 sec)Now you can insert records in the table using insert command. The query is as follows −mysql> insert into gettingLast5Characters values('Introduction ... Read More

Order of Events of Republic Day Celebration at Red Fort

Ridhi Arora
Updated on 30-Jul-2019 22:30:24

845 Views

Republic day in India is celebrated on 26th of January every year and holds a seminal value. The day is celebrated in grandeur in the capital city's India Gate. Various events take place in the capital city and elsewhere to celebrate the framing of the Indian Constitution.Order of Events On Republic DayPrime Minister lays a floral wreath at Amar Jawan Jyoti. It is an Indian memorial constructed post the Indo-Pakistani War of 1971 to commemorate the martyred soldiers of the Indian Armed Forces who died during the war.President along with his bodyguards proceeds to the parade ground in Red Fort. ... Read More

Use headset() Method of Java NavigableSet Class

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

120 Views

The headset() method returns elements up to a limit defined as a parameter.First, create a NavigableSet and add elements −NavigableSet set = new TreeSet(); set.add(10); set.add(25); set.add(40); set.add(55); set.add(70); set.add(85); set.add(100);Now, use the headset() method −set.headSet(55));The following is an example −Example Live Demoimport java.util.NavigableSet; import java.util.TreeSet; public class Demo {    public static void main(String[] args) {       NavigableSet set = new TreeSet();       set.add(10);       set.add(25);       set.add(40);       set.add(55);       set.add(70);       set.add(85);       set.add(100);       System.out.println("Returned Value = " + ... Read More

Removing Single Elements in a Vector in Java

Rishi Raj
Updated on 30-Jul-2019 22:30:24

166 Views

A single element in the Vector can be removed using the java.util.Vector.remove() method. This method removes the element at the specified index in the Vector. It returns the element that was removed. Also after the element is removed from the specified index, the rest of the Vector elements are shifted to the left.A program that demonstrates this is given as follows:Example Live Demoimport java.util.Vector; public class Demo { public static void main(String args[]) { Vector vec = new Vector(5); vec.add(4); ... Read More

Raise X to the Power N Using Recursion in Java

Vikyath Ram
Updated on 30-Jul-2019 22:30:24

786 Views

The power of a number can be calculated using recursion. Here the number is x and it is raised to power n.A program that demonstrates this is given as follows:Example Live Demopublic class Demo {    static double pow(double x, int n) {       if (n != 0)          return (x * pow(x, n - 1));       else          return 1;    }    public static void main(String[] args) {       System.out.println("7 to the power 3 is " + pow(7, 3));       System.out.println("4 to the power 1 ... Read More

Advertisements