Absolute Difference Between Product of Non-Prime and Prime Numbers of an Array

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

229 Views

Here we will see how we can find the absolute difference between the product of all prime numbers and all non-prime numbers of an array. To solve this problem, we have to check whether a number is prime or not. One possible way for primality testing is by checking a number is not divisible by any number between 2 to square root of that number. So this process will take 𝑂(√𝑛) amount of time. Then get the product and try to find the absolute difference.AlgorithmdiffPrimeNonPrimeProd(arr)begin    prod_p := product of all prime numbers in arr    prod_np := product of ... Read More

Difference Between Set, Multiset, Unordered Set, and Unordered Multiset in C++

Anvi Jain
Updated on 30-Jul-2019 22:30:26

386 Views

Here we will see what are the differences for set, multiset, unordered_set and unordered_multiset in C++. Let us see the properties of them using some example.SetThe properties of set are like belowStores data in sorted orderStores only unique valuesWe can insert or delete data, but cannot change the dataWe can remove more than one element using start and end iteratorWe can traverse using iteratorsSets are implemented using Binary Search TreeNow let us see an exampleExample#include #include using namespace std; main() {    int data[15] = {11, 55, 22, 66, 33, 22, 11, 44, 77, 88, 66, 99, 66, 23, 41};    set my_set;    for(int i = 0; i

Display Count of Notifications in Toolbar Icon in Android

Smita Kapse
Updated on 30-Jul-2019 22:30:26

687 Views

This example demonstrate about How to display count of notifications in toolbar icon in Android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.                                                                                                 ... Read More

Get All Collections Where Collection Name Like 2015

Smita Kapse
Updated on 30-Jul-2019 22:30:26

589 Views

Let us first create some collections that starts from year number i.e. 2015, 2019, etc −> use web; switched to db web > db.createCollection("2015-myCollection"); { "ok" : 1 } > db.createCollection("2019-employeeCollection"); { "ok" : 1 } > db.createCollection("2015-yourCollection"); { "ok" : 1 }Now you can display all the collections with the help of SHOW −> show collections;This will produce the following output −2015-myCollection 2015-yourCollection 2019-employeeCollection applyConditionDemo check creatingAliasDemo emp_info emptyCollection removeNullDemoFollowing is the query to get all collections where collection name like ‘%2015%’ −> db.getCollectionNames().filter(function (v) { return /^2015\-/.test(v); })This will produce the following output −[ "2015-myCollection", "2015-yourCollection" ]If you ... Read More

Disable a Tab in a JTabbedPane Container with Java

George John
Updated on 30-Jul-2019 22:30:26

3K+ Views

To disable a tab in a JTabbedPane container, use the setEnabledAt() method and set it to false with the index of the tab you want to disable.Let’s first create a JTabbedPane −JTabbedPane tabbedPane = new JTabbedPane();Now, let us disable a tab at index 2 −tabbedPane.setEnabledAt(2, false);The following is an example to disable a tab in a JTabbedPane Container −Examplepackage my; import javax.swing.*; import java.awt.*; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Devices");       JTabbedPane tabbedPane = new JTabbedPane();       JTextArea text = new JTextArea(100, 100); ... Read More

Get Rows with GROUP BY in MySQL

Ankith Reddy
Updated on 30-Jul-2019 22:30:26

255 Views

Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Subject varchar(20),    Price int    ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Subject, Price) values('MySQL', 456); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(Subject, Price) values('MySQL', 456); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(Subject, Price) values('MongoDB', 56); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(Subject, Price) values('MongoDB', 60); Query OK, 1 row affected (0.13 sec) mysql> ... Read More

Store and Retrieve Boolean Values in Varchar2 Column Using JDBC

Anvi Jain
Updated on 30-Jul-2019 22:30:26

633 Views

Yes, in Oracle you can store and retrieve a boolean value into a table for a column with VARCHAR2 datatype.If you do so, the true and false values are stored as 1 and 0 and the retrieved as same (respectively).ExampleLet us create a table with name sampleTable in the Oracle database Using CREATE statement as −CREATE TABLE sampleTable(    ID INT,    ProductName VARCHAR (20) NOT NULL,    CustomerName VARCHAR (20) NOT NULL,    IsBillDue VARCHAR (20) NOT NULL,    DeliveryDate date,    Price INT,    Location varchar(20) );The column IsBillDue specified whether bill paid.Following JDBC program establishes the connection ... Read More

Extract Substring from a String Starting at a Particular Position in MySQL

Kumar Varma
Updated on 30-Jul-2019 22:30:26

271 Views

For this, you can use the mid() function. Following is the syntax −select mid(yourColumnName, yourPositionToStart, yourEndValue) as anyAliasName from yourTableName;Let us first create a table −mysql> create table DemoTable    -> (    -> Title text    -> ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('My best framework is Spring and Hibernate'); Query OK, 1 row affected (0.21 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+-------------------------------------------+ | Title ... Read More

Absolute Difference Between the Sum of Non-Prime and Prime Numbers of an Array

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

258 Views

Here we will see how we can find the absolute difference between the sum of all prime numbers and all non-prime numbers of an array. To solve this problem, we have to check whether a number is prime or not. One possible way for primality testing is by checking a number is not divisible by any number between 2 to square root of that number. So this process will take 𝑂(√𝑛) amount of time. Then get the sum and try to find the absolute difference.AlgorithmdiffPrimeNonPrimeSum(arr)begin    sum_p := sum of all prime numbers in arr    sum_np := sum of ... Read More

When to Use Yield Instead of Return in Python

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

1K+ Views

In short, whenever control reach the return statement in your program, the execution of the program is terminated and the remaining statements will not executed.However, in case of yield, whenever control reach the yield statement in your program, the execution of your program is paused and later we can continue other statements in function.Let’s understand both the statements in detail.YieldUsing yield statement in a function makes the function a generator function which can be used in a loop. When the function is running and the yield statement exeucutes, the value after the yield is passed back to the loop that ... Read More

Advertisements