Swapping variables has become very easy with destructuring. In contemporary javascript swapping takes place by using another variable. It may not be hectic but it is lengthy. But in modern javascript there is no need for the third variable. Let's discuss it in detail.Example-1In the following example, swapping has done using another variable called "temp". Therefore the code got lengthier. Live Demo var a = "Sachin"; var b = "Tendulkar"; document.write("Before swapping-"+ " "+ a + " " +b); var tmp = a; a = b; ... Read More
We can attach two strings using the concat() method. But if we need to attach a specific string at the starting of the first string then the easiest way is string.padStart(). This method not only adds the second string at the start of the first string but also looks after the number of characters to be added. It basically takes two parameters one is the length and the other is second string. The method string.padStart() add the second string to the first based on the length provided to it.syntaxstring.padStart(length, "string");It takes the length as the parameter to concise the resulted string to those ... Read More
A decagonal number is a figurate that was derived using the concept of triangular numbers and square numbers. This extension of number pattern is created using non-rotationally symmetrical numbers. This nested decagon oriented number is given by the number of dots in the number of nested decagons that are created. For example, for 3rd decagonal number 3 decagonal figures are nest each with iX time the number of sides in the decagon. As shown in figure −Side in 1st Outer figure = 30 Side in 2nd Outer figure = 20 Side in inner figure = 10 Sides common in all = 6+2 Total = 30+20+10-(6+2) ... Read More
An interface in Java is similar to class but, it contains only abstract methods and fields which are final and static.Just like classes you can extend one interface from another using the extends keyword as shown below −interface ArithmeticCalculations{ public abstract int addition(int a, int b); public abstract int subtraction(int a, int b); } interface MathCalculations extends ArithmeticCalculations{ public abstract double squareRoot(int a); public abstract double powerOf(int a, int b); }But, when you implement the sub-class you need to provide body for the abstract methods in both interfaces.ExampleIn the following example we have created two interfaces ... Read More
A program to add 1 to a given number increments the value of the variable by 1 . This is general used in counters.There are 2 methods to increase that can be used to increase a given number by 1 −Simple adding of one to the number and reassigning it to the variable.Using increment operator in the program.Method 1 − using reassignment methodThis method takes the variable, add 1 to it and then reassigns its value.Example Code Live Demo#include int main(void) { int n = 12; printf("The initial value of number n is %d ", n); n ... Read More
To swap data between two columns in MySQL, use the concept of variable. Let us first create a table. Here, we will swap Name1 with Name2 −mysql> create table DemoTable -> ( -> Name1 varchar(100), -> Name2 varchar(100) -> ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John Smith', 'Chris Brown'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('David Miller', 'Jone Doe'); Query OK, 1 row affected (0.16 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will produce ... Read More
Let us first create a table −mysql> create table DemoTable -> ( -> Id int, -> Score int -> ); Query OK, 0 rows affected (0.69 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(1, 858858686); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(2, 9900554); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values(3, 646565667); Query OK, 1 row affected (0.15 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will produce the following output −+------+-----------+ | Id ... Read More
For this, use CASE statement. Let us first create a table −mysql> create table DemoTable -> ( -> Title text -> ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('My name is John and this is my first tutorial on MySQL'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('This is Carol and I work on MongoDB'); Query OK, 1 row affected (0.19 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will produce the following output −+--------------------------------------------------------+ | Title ... Read More
Use DEFAULT keyword at the time of table creation and it will insert default value whenever you do not provide the value for that column.Let us first create a table. Here, for ClientAge, we have set the default 24:Let us first create a table. Here, for ClientAge, we have set the default 24 −mysql> create table DemoTable -> ( -> ClientId int AUTO_INCREMENT PRIMARY KEY, -> ClientName varchar(100), -> ClientAge int DEFAULT 24 -> ); Query OK, 0 rows affected (0.49 sec)Insert some records in the table using insert command. For values which are not ... Read More
Let us first create a table −mysql> create table DemoTable -> ( -> Amount int -> ); Query OK, 0 rows affected (0.99 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(200); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(500); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will produce the following output −+--------+ | Amount | +--------+ | 100 | | 200 ... Read More