Middle of Three Using Minimum Comparisons in C++

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

650 Views

In this section, we will see how to find the middle of three given values by comparing them. So if three numbers are given like (10, 30, 20), then it will find 20 as this is the middle element. Let us see the algorithm first, then we will implement that algorithm into C++ code.Algorithmmiddle_of_three(a, b, c): Input: Three numbers a, b and c Output: The middle of these three Begin    if a > b, then       if b > c, then          return b       else if a > c, then   ... Read More

Get the List of All Databases Using JDBC

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

3K+ Views

You can get the list of databases in MySQL using the SHOW DATABASES query.show databases;Following JDBC program retrieves the list of databases by executing the show databases query.Exampleimport java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class ShowDatabasesExample {    public static void main(String args[]) throws Exception {       //Registering the Driver       DriverManager.registerDriver(new com.mysql.jdbc.Driver());       //Getting the connection       String mysqlUrl = "jdbc:mysql://localhost/mydatabase";       Connection con = DriverManager.getConnection(mysqlUrl, "root", "password");       System.out.println("Connection established......");       //Creating a Statement object       Statement stmt = con.createStatement(); ... Read More

Find Maximum Value of an Array in JavaScript

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

1K+ Views

we can find the Maximum value of an array using Math.max() and sort() functions.1) Math.max()Math.max() function usually takes all the elements in an array and scrutinize each and every value to get the maximum value.It's methodology is discussed in the below example. Live DemoExample    function maximum(value) { if (toString.call(value) !== "[object Array]") return false; return Math.max.apply(null, value); } document.write(maximum([6, 39, 55, 1, 44])); Output55.2) sort()Using sort and compare functions we can ... Read More

Check If a List Is Not Empty in MongoDB

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

436 Views

For this, use the $size operator. Let us first create a collection with documents −> db.checkIfListIsNotEmptyDemo.insertOne({"UserFriendGroup":["John", "David"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cdd99e8bf3115999ed511f7") } > db.checkIfListIsNotEmptyDemo.insertOne({"UserFriendGroup":["Carol"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cdd99e9bf3115999ed511f8") } > db.checkIfListIsNotEmptyDemo.insertOne({"UserFriendGroup":[]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cdd99ebbf3115999ed511f9") } > db.checkIfListIsNotEmptyDemo.insertOne({"UserFriendGroup":[null]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cdd99f2bf3115999ed511fa") } > db.checkIfListIsNotEmptyDemo.insertOne({"UserFriendGroup":[]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cdd99f6bf3115999ed511fb") }Following is the query to display all documents from a collection with the help of find() method −> db.checkIfListIsNotEmptyDemo.find().pretty();This will produce the following output −{   ... Read More

C Function Argument and Return Values

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

9K+ Views

Here we will see what are the different types of C functions based on the return values and arguments.So a function either can take some arguments, or nothing is taken. Similarly, a function can return something, otherwise does not return anything. So we can categorize them into four types.Function with No argument and No return type.Function with No argument and Return something.A function that takes argument but returns nothing.Functions that take an argument and also return something.Example#include void my_function() {    printf("This is a function that takes no argument, and returns nothing."); } main() {    my_function(); }OutputThis is ... Read More

Difference Between Destructor and Free Function in C++

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

608 Views

Here we will see what are the differences between destructor and the free() functions in C++. The destructor is used to perform some action, just before the object is destroyed. This action may not freeing up the memory, but can do some simple action such as displaying one message on screen.The free() function is used in C, in C++, we can do the same thing using delete keyword also. When the object is deleted using free() or delete, the destructor is invoked. The destructor function takes no argument and returns nothing. This function is called when free or delete is ... Read More

Get All Column Names from a ResultSet Using JDBC

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

17K+ Views

You can get the name of a particular column using the getColumnName() method of the ResultSetMetadata interface.This method accepts an integer value representing the index of a column and returns a String value representing the name of the specified column.Let us create a table with name MyPlayers in MySQL database using CREATE statement as shown below −CREATE TABLE MyPlayers(    ID INT,    First_Name VARCHAR(255),    Last_Name VARCHAR(255),    Date_Of_Birth date,    Place_Of_Birth VARCHAR(255),    Country VARCHAR(255),    PRIMARY KEY (ID) );Now, we will insert 7 records in MyPlayers table using INSERT statements −insert into MyPlayers values(1, 'Shikhar', 'Dhawan', DATE('1981-12-05'), 'Delhi', 'India'); insert into MyPlayers ... Read More

Find Minimum Value of an Array in JavaScript

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

3K+ Views

We can find the minimum value of an array using Math.min() and sort()1) Math.min() Math.min() function usually takes all the elements in an array and scrutinize each and every value to get the minimum value.It's methodology is discussed in the below example. Live DemoExample    function minimum(value) {       if (toString.call(value) !== "[object Array]")       return false;       return Math.min.apply(null, value);    }    document.write(minimum([6, 39, 55, 1, 44])); Output12)  sort()Using sort() and compare functions we can write the elements in ascending or descending order, later on using length property we can ... Read More

Select or Deselect Rows in Table Model in Java

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

429 Views

We can set or disallow selection of row in the table using setRowSelectionAllowed().Let’s say the following is our table −DefaultTableModel tableModel = new DefaultTableModel(); JTable table = new JTable(tableModel);If you want to allow selection of row, then set the method to TRUE −table.setRowSelectionAllowed(true);If you want to disallow selection of row, then set the method to FALSE −table.setRowSelectionAllowed(false);We have disallowed selection of rows in the below example −Examplepackage my; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; public class SwingDemo {    public static void main(String[] argv) throws Exception {       DefaultTableModel tableModel = new DefaultTableModel();       ... Read More

Difference Between Map and WeakMap in JavaScript

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

4K+ Views

Differences between Map and WeakMapThe functional mechanism of Map and WeakMap is same but they have little differences.1) A WeakMap accepts only objects as keys whereas a Map, in addition to objects, accepts primitive datatype such as strings, numbers etc.2) WeakMap objects doesn't avert garbage collection if there are no references to the object which is acting like a key. Therefore there is no method to retrieve keys in WeakMap, whereas in Map there are methods such as Map.prototype.keys() to get the keys.3) There is no size property exists in WeakMap.MapIt is used to associate a key to a value ... Read More

Advertisements