Print N Terms of Newman Conway Sequence

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

414 Views

Newman-Conway Sequence is used for generating following integer sequence.1 1 2 2 3 4 4 4 5 6 7 7 8 8 8 8 9 10 11 12Formula used for generating Newman-Conway sequence for n numbers is −P(n) = P(P(n - 1)) + P(n - P(n - 1)) Where, p(1) =p(2) =1AlgorithmSTART Step 1 -> Input variable n(e.g. 20) Step 2 -> start variables as i, p[n+1], p[1]=1, p[2]=1 Step 3 -> Loop For i=3 and i End Loop For STOPExample#include int main() {    int n = 20,i;    int p[n + 1];    p[1] = 1;    p[2] = 1;    printf("Newman-Conway Sequence is :");    printf("%d %d ",p[1],p[2]);    for (i = 3; i

Check for Existing Document in MongoDB

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

149 Views

You can use findOne() for this. Following is the syntax −db.yourCollectionName.findOne({yourFieldName: 'yourValue'});Let us create a collection with documents −> db.checkExistingDemo.insertOne({"StudentName":"John"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbdf90dac184d684e3fa265") } > db.checkExistingDemo.insertOne({"StudentName":"Carol"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbdf912ac184d684e3fa266") } > db.checkExistingDemo.insertOne({"StudentName":"Sam"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbdf916ac184d684e3fa267") } > db.checkExistingDemo.insertOne({"StudentName":"Mike"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbdf91bac184d684e3fa268") }Display all documents from a collection with the help of find() method −> db.checkExistingDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cbdf90dac184d684e3fa265"), "StudentName" : "John" } { "_id" : ObjectId("5cbdf912ac184d684e3fa266"), "StudentName" : "Carol" } ... Read More

Create JCheckBox from Text in Swing

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

191 Views

The following is an example to create JCheckBox from text in Swing:Exampleimport java.awt.FlowLayout; import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JLabel; public class SwingDemo {    public static void main(String[] args) {       JCheckBox checkBox1 = new JCheckBox("Cricket");       JCheckBox checkBox2 = new JCheckBox("Squash");       JCheckBox checkBox3 = new JCheckBox("Football");       checkBox3.setSelected(true);       JCheckBox checkBox4 = new JCheckBox("Hockey");       JCheckBox checkBox5 = new JCheckBox("Fencing");       JCheckBox checkBox6 = new JCheckBox("Tennis");       JFrame frame = new JFrame();       frame.setLayout(new FlowLayout());       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);   ... Read More

Make Notification Intent Resume Instead of Creating New Intent

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

535 Views

This example demonstrate about How to make notification intent resume rather than making a new intentStep 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.     Step 3 − Add the following code to src/MainActivity.javapackage app.tutorialspoint.com.notifyme ; import android.app.NotificationChannel ; import android.app.NotificationManager ; import android.app.PendingIntent ; import android.content.Context ; import android.content.Intent ; import android.support.v4.app.NotificationCompat ; import android.support.v7.app.AppCompatActivity ; import android.os.Bundle ; import android.view.View ; import android.widget.Button ; public class MainActivity extends AppCompatActivity {   ... Read More

Pull All Elements from an Array in MongoDB

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

331 Views

You can use $set operator for this. Let us first create a collection with documents −> db.pullAllElementDemo.insertOne( ...    { ...       "StudentId":101, ...       "StudentDetails" : [ ...          { ... ...             "StudentName": "Carol", ...             "StudentAge":21, ...             "StudentCountryName":"US" ...          }, ...          { ...             "StudentName": "Chris", ...             "StudentAge":24, ...             ... Read More

Implement Constants in Java

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

1K+ Views

A constant variable is the one whose value is fixed and only one copy of it exists in the program. Once you declare a constant variable and assign value to it, you cannot change its value again throughout the program.You can create a constant in c language using the constant keyword (one way to create it) as −const int intererConstant = 100; or, const float floatConstant = 16.254; ….. etcConstants in javaUnlike in C language constants are not supported in Java(directly). But, you can still create a constant by declaring a variable static and final.Static − Once you declare a ... Read More

HTML DOM Input Month Object

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

162 Views

The HTML DOM input month Object represent the element with type=”month”.Let us create input month object −SyntaxFollowing is the syntax −var monthInput = document.createElement(“INPUT”); monthInput.setAttribute(“type”, ”month”);PropertiesFollowing are the properties of HTML DOM input month Object −PropertyExplanationautocompleteIt returns and alter the value of the autocomplete attribute of month input field.autofocusIt returns and modify whether the input month field should get focused or not when page load.disabledIt returns and modify whether the input month field is disabled or not.defaultValueIt returns and alter the default value of the input month field.formIt returns the reference of the form that contain the input month ... Read More

A Product Array Puzzle in C++

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

296 Views

Here we will see one interesting problem related to array. There is an array with n elements. We have to create another array of n elements. But the i-th position of second array will hold the product of all elements of the first array except the i-th element. And one constraint is that we cannot use the division operator in this problem.If we can use the division, operation, we can easily solve this problem, by getting the product of all elements, then divide i-th element of first array and store it into i-th place of the second array.Here we are ... Read More

Print N Smallest Elements from Given Array in Original Order

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

259 Views

Given with array of let’s say k elements the program must find the n smallest elements amongst them in their appearing order.Input : arr[] = {1, 2, 4, 3, 6, 7, 8}, k=3 Ouput : 1, 2, 3 Input k is 3 it means 3 shortest elements among the set needs to be displayed in original order like 1 than 2 and than 3AlgorithmSTART Step 1 -> start variables as int i, max, pos, j, k=4 and size for array size Step 2 -> Loop For i=k and i=0 and j--       If arr[j]>max         ... Read More

Get Attribute List from MongoDB Object

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

1K+ Views

To get attribute list from MongoDB object, you can use for loop to extract key and value for document. Let us create a collection with documents −>db.getAttributeListDemo.insertOne({"StudentId":101, "StudentName":"John", "StudentAdmissi onDate":new ISODate('2019-01-12'), "StudentSUbjects":["MongoDB", "Java", "MySQL"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbdfcc9ac184d684e3fa269") }Display all documents from a collection with the help of find() method −> db.getAttributeListDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cbdfcc9ac184d684e3fa269"),    "StudentId" : 101,    "StudentName" : "John",    "StudentAdmissionDate" : ISODate("2019-01-12T00:00:00Z"),    "StudentSUbjects" : [       "MongoDB",       "Java",       "MySQL"    ] }Following is the ... Read More

Advertisements