Find K Numbers Closest to Median in C++

Samual Sam
Updated on 30-Jul-2019 22:30:26

207 Views

This is a C++ Program to find k numbers closest to Median of S, where S is a set of n numbers.AlgorithmsBegin    function partition() for partitioning the array on the basis of values at high as pivot value:    Arguments:       a[]=an array.       l=low    H=high    Body of the function:    Declare variables pivot, in, i    Initialize in = l    Set pivot = h    For i=l to h-1       if(a[i] < a[pivot])          swap a[i] and a[in])       increment in.       ... Read More

Get Driver Minor Version in Java DatabaseMetadata

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

141 Views

The getDriverMinorVersion() method of the DatabaseMetaData interface returns the minor version of the JDBC driver used.To get the minor version of the JDBC driver used to connect with the database −Make sure your database is up and running.Register the driver using the registerDriver() method of the DriverManager class. Pass an object of the driver class corresponding to the underlying database.Get the connection object using the getConnection() method of the DriverManager class. Pass the URL the database and, user name, password of a user in the database, as String variables.Get the DatabaseMetaData object with respect to the current connection using the ... Read More

Select Random Number from a Specific List in MySQL

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

2K+ Views

You can use elt() along with rand() for this. Let us select random number from a specific list.mysql> SELECT ELT(FLOOR(RAND() * 10) + 1,    100, 200, 300, 400, 500, 600, 700, 800, 900, 1000) AS random_value_from_listOfValues;This will produce the following output −+--------------------------------+ | random_value_from_listOfValues | +--------------------------------+ | 1000 | +--------------------------------+ 1 row in set (0.00 sec)Now we will run the query again to select random number from a specific list.mysql> SELECT ELT(FLOOR(RAND() * ... Read More

Selection Modes in JTable with Java

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

970 Views

Selection modes sets the table's selection mode to allow only single selections, a single contiguous interval, or multiple intervals. Let us see the selection modes one by one −Single Selection modeThe following is an example of Single Selection mode for a JTable. It allows you to select one cell at a time −Examplepackage my; import java.awt.Color; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.ListSelectionModel; import javax.swing.border.TitledBorder; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame();       JPanel panel = new JPanel();       ... Read More

Query Array of Nested String with MongoDB

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

214 Views

To query array of nested string, you can use the dot(.) notation. Let us first create a collection with documents −> db.nestedStringDemo.insertOne(    {       "CustomerName": "John",       "CustomerOtherDetails": [ { "Age":29, "CountryName": "US" },       { "CompanyName": "Amazon",       "Salary": 150000, "ProjectName": ["Online Library Management System", "Pig Dice Game"]    } ] } ); {    "acknowledged" : true,    "insertedId" : ObjectId("5cea4629ef71edecf6a1f690") } > db.nestedStringDemo.insertOne( {    "CustomerName": "Chris",    "CustomerOtherDetails": [ { "Age":27, "CountryName": "AUS" },    { "CompanyName": "Google",       "Salary": 250000, "ProjectName": ["Chat Application", "Game ... Read More

Importance of Import Keyword in Java

Venkata Sai
Updated on 30-Jul-2019 22:30:26

545 Views

In Java classes and interfaces related to each other are grouped under a package. Package is nothing but a directory storing classes and interfaces of a particular concept. For example, all the classes and interfaces related to input and output operations are stored in java.io package.There are two types of packages namely user-defined packages and built-in packages (pre-defined)The import keywordWhenever you need to use the classes from a particular package −First of all, you need to set class path for the JAR file holding the required package.Import the required class from the package using the import keyword. While importing you ... Read More

Sum of First N Natural Numbers Divisible by X or Y

Sharon Christine
Updated on 30-Jul-2019 22:30:26

690 Views

Adding up all natural numbers up to n, that are divisible by X or Y is selecting all the numbers that are divisible by X or Y and adding them to a variable that stores the sum.To find the sum of the first N natural numbers which are divisible by X or Y, there are two methods −Using loops and conditional statementsUsing formulaMethod 1 − Using loops and conditional statementsThis method uses a loop that counts up to n numbers and selects numbers that are divisible by X or Y and adds them and save to a variables at each ... Read More

Difference Between Selenium 2 and Selenium 3

Adiya Dua
Updated on 30-Jul-2019 22:30:26

4K+ Views

Selenium 2Selenium2 is nothing but integration of WebDriver with Selenium RC(Selenium1). Selenium 1 is a well-established framework that supports various many browsers due to its JavaScript implementation. To step out of JavaScript Sandbox, WebDriver is developed for each browser which provides a headless browser emulator which is very speedy. The strengths of both WebDriver and Selenium 1 are imbibed in Selenium2 which also helps in getting rid of their respective drawbacks.Selenium 3For users of WebDriver API’s, this is a drop-in replacement. The major change being, removing the core and replacing it with the back-end WebDriver. Selenium 3.0 has become a ... Read More

Find i-th Largest Number Using Order Statistic Algorithm in C++

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

228 Views

This is a C++ program to find ith largest number from a given list using Order-Statistic Algorithm.AlgorithmsBegin    function Insert() to insert nodes into the tree:    Arguments:       root, d.       Body of the function:       If tree is completely null then insert new node as root.       If d = tmp->data, increase the count of that particular node.       If d < tmp->data, move the tmp pointer to the left child.       If d > tmp->data, move the tmp pointer to the right child. End Begin ... Read More

Does MySQL DROP TABLE Completely Remove the Table?

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

136 Views

The DROP TABLE removes the table completely and also removes all data. If you want to remove all data completely and wants the table structure, then you can use TRUNCATE TABLE command. The TRUNCATE command will recreate the table.Let us first check the DROP TABLE. For that, we will first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(20)    ); Query OK, 0 rows affected (0.20 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name) values('Larry'); Query OK, 1 row affected (0.07 sec) ... Read More

Advertisements