Print N lines of numbers such that every pair among numbers has a GCD K

Sunidhi Bansal
Updated on 30-Jul-2019 22:30:26

106 Views

GCDGCD stands for Greatest Common Divisor of two or more integers excluding 0Like, to find the greatest common divisor of 48 and 18048 = 2 × 2 × 2 × 2 × 3180 = 2 × 2 × 3 × 3 × 5Greatest common divisor = 2 × 2 × 3 = 12.In the given problem, N lines should be printed with elements have GCD as specifiedInput : N=2 GCD=2 Ouput : 2-4-6-10 14-16-18-22AlgorithmSTART Step 1 -> take input n(e.g. 2) and k(e.g. 2) as int values and i Step 2-> Loop For i to 0 and i end loop ... Read More

How to implement a copy constructors in C++?

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

380 Views

Here we will see how the copy constructors are implemented in C++. Before discussing that we should know what is the copy constructor.The copy constructor is a constructor which creates an object by initializing it with an object of the same class, which has been created previously. The copy constructor is used to −Initialize one object from another of the same type.Copy an object to pass it as an argument to a function.Copy an object to return it from a function.If a copy constructor is not defined in a class, the compiler itself defines one. If the class has pointer ... Read More

How to change Button Border in Java Swing

Krantik Chavan
Updated on 30-Jul-2019 22:30:26

724 Views

For Button border, use createLineBorder() method in Java, which allows you to set the color of the Border as well:JButton button = new JButton("Demo Button!"); Border border = BorderFactory.createLineBorder(Color.BLUE);The following is an example to change button border in Java:Exampleimport java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.border.Border; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Button Border");       Container container = frame.getContentPane();       JButton button = new JButton("Demo Button!");       Border border = BorderFactory.createLineBorder(Color.BLUE);       button.setBorder(border);   ... Read More

Java DatabaseMetaData supportsStoredProcedures() method with example

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

30 Views

The supportsStoredProcedures() method of the DatabaseMetaData interface is used to determine whether the underlying database supports stored procedures.This method returns a boolean value which is −True, when the underlying database supports stored procedures.False, when the underlying database doesn't support stored procedures.To determine whether the underlying database supports stored procedures−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 ... Read More

What is the syntax for boolean values in MongoDB?

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

5K+ Views

You can use $eq as well as $ne operator for boolean values. Let us first create a collection with documents −> db.booleanQueryDemo.insertOne({"UserName":"John", "UserAge":23, "isMarried":true}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc815c08f9e6ff3eb0ce44a") } > db.booleanQueryDemo.insertOne({"UserName":"Chris", "UserAge":21, "isMarried":false}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc815d08f9e6ff3eb0ce44b") } > db.booleanQueryDemo.insertOne({"UserName":"Robert", "UserAge":24, "isMarried":false}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc815dc8f9e6ff3eb0ce44c") } > db.booleanQueryDemo.insertOne({"UserName":"David", "UserAge":26, "isMarried":true}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc815ed8f9e6ff3eb0ce44d") }Following is the query to display all documents from a collection with the help of find() method −> db.booleanQueryDemo.find().pretty();This will produce the following output −{ ... Read More

Templates in C++ vs Generics in Java

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

2K+ Views

Templates are the foundation of generic programming, which involves writing code in a way that is independent of any particular type.A template is a blueprint or formula for creating a generic class or a function. The library containers like iterators and algorithms are examples of generic programming and have been developed using template concept.There is a single definition of each container, such as vector, but we can define many different kinds of vectors for example, vector or vector .Example Code#include #include using namespace std; template inline T const& Max (T const& a, T const& b) { ... Read More

How to create Vertical progress bar occupying the entire frame in Java

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

145 Views

For this, create a vertical progress bar −JProgressBar progressBar = new JProgressBar(JProgressBar.VERTICAL); progressBar.setEnabled(true);Also, set the bounds −progressBar.setBounds(70, 50, 120, 30);The following is an example to create vertical progress bar occupying the entire frame −Examplepackage my; import java.awt.BorderLayout; import java.awt.Color; import javax.swing.JFrame; import javax.swing.JProgressBar; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame();       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       JProgressBar progressBar = new JProgressBar(JProgressBar.VERTICAL);       progressBar.setEnabled(true);       progressBar.setBounds(70, 50, 120, 30);       progressBar.setBackground(Color.orange);       progressBar.setForeground(Color.white);       progressBar.setStringPainted(true);       ... Read More

Merge two array fields in MongoDB?

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

540 Views

To merge, use $setUnion operator. Let us first create a collection with documents −> db.mergeTwoArrayFieldDemo.insertOne({"NaturalNumbers":[1,2,3,8,10,20,30],"WholeNumbers":[0,1,2,63,78,20,45]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd68e4057806ebf1256f11d") }Following is the query to display all documents from a collection with the help of find() method −> db.mergeTwoArrayFieldDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cd68e4057806ebf1256f11d"),    "NaturalNumbers" : [       1,       2,       3,       8,       10,       20,       30    ],    "WholeNumbers" : [       0,       1,       2,       63,       78,       20,       45    ] }Following is the query to merge two array field in MongoDB.> db.mergeTwoArrayFieldDemo.aggregate([    { "$project": {       "MergedArray": { "$setUnion": [ "$NaturalNumbers", "$WholeNumbers" ] }    }} ]);This will produce the following output −{ "_id" : ObjectId("5cd68e4057806ebf1256f11d"), "MergedArray" : [ 0, 1, 2, 3, 8, 10, 20, 30, 45, 63, 78 ] }

How to use use an array of pointers (Jagged) in C/C++?

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

500 Views

Let us consider the following example, which uses an array of 3 integers −In CExample Live Demo#include const int MAX = 3; int main () {    int var[] = {10, 100, 200};    int i;    for (i = 0; i < MAX; i++) {       printf("Value of var[%d] = %d", i, var[i] );    }    return 0; }OutputValue of var[0] = 10 Value of var[1] = 100 Value of var[2] = 200In C++Example Live Demo#include using namespace std; const int MAX = 3; int main () {    int var[] = {10, 100, 200};    int i;    for (i = 0; i < MAX; i++) {       cout

What are the different types of nested classes are defined in Java?

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

766 Views

In Java, it is possible to define a class inside another class, such classes are called Nested classes. We can use the access modifiers like private, public, protected or default for inner classes and default or public access modifiers for outer class.There are two types of nested classes are defined in Java.Static Nested ClassNon-Static Nested ClassStatic Nested ClassWe Can define an inner class as static, so such type of classes is called a static nested class.The nested class is defined with the static keyword, so this type of nested classes doesn’t share any relationship with the instance of an outer class.A static ... Read More

Advertisements