A C Programming Language Puzzle

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

502 Views

Here we will see one C programming language puzzle question. Suppose we have two numbers 48 and 96. We have to add the first number after the second one. So final result will be like 9648. But we cannot use any logical, arithmetic, string related operations, also cannot use any pre-defined functions. So how can we do that?This is easy. We can do by using Token Pasting operator(##) in C. The Token Pasting operator is a preprocessor operator. It sends commands to compiler to add or concatenate two tokens into one string. We use this operator at the macro definition.Example Live ... Read More

Convert File into a Stream in Java

Nancy Den
Updated on 30-Jul-2019 22:30:26

748 Views

Let’s say we have a file “input.txt” here in the directory E:/ with the following content:Open a file with Bufferedreader. We have taken the above file here which is located at E: directory;BufferedReader buffReader = Files.newBufferedReader(Paths.get("E:\input.txt"), StandardCharsets.UTF_8);Now get the stream of lines from the above file and display:buffReader.lines().forEach(System.out::println);The following is an example to convert File into a Stream in Java:Exampleimport java.io.BufferedReader; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; public class Demo {    public static void main(String[] argv) throws Exception {       BufferedReader buffReader = Files.newBufferedReader(Paths.get("E:\input.txt"), StandardCharsets.UTF_8);       System.out.println("Stream of lines...");       buffReader.lines().forEach(System.out::println);    } ... Read More

Set Action Command to JButton in Java

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

4K+ Views

With set action command, here we are displaying a message in the console on the click of a button.Set the button first:JButton btn = new JButton("Demo Button");Now, set Action Listener to fire when the button is clicked:ActionListener actionListener = new ActionListener() {    public void actionPerformed(ActionEvent event) {       String str = event.getActionCommand();       System.out.println("Clicked = " + str);    } };The following is an example to set action command to JButton:Exampleimport java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JOptionPane; public class SwingDemo {    public static void main(final String args[]) {       JButton btn ... Read More

Display Multiple Notifications in Android

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

997 Views

This example demonstrate about How to display multiple notifications in androidStep 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 a sound into raw folderStep 4 − Add the following code to src/MainActivity.javapackage app.tutorialspoint.com.notifyme ; import android.app.NotificationChannel ; import android.app.NotificationManager ; import android.content.ContentResolver ; import android.content.Context ; import android.graphics.Color ; import android.media.AudioAttributes ; import android.net.Uri ; import android.support.v4.app.NotificationCompat ; import android.support.v7.app.AppCompatActivity ; import android.os.Bundle ; import android.view.View ; import ... Read More

Increment a Field in MongoDB

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

390 Views

To increment a field in MongoDB, you can use $inc operator. Let us first create a collection with documents −> db.incrementDemo.insertOne({"PlayerScore":100}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc81cdd8f9e6ff3eb0ce44e") } > db.incrementDemo.insertOne({"PlayerScore":290}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc81ce28f9e6ff3eb0ce44f") } > db.incrementDemo.insertOne({"PlayerScore":560}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc81ce68f9e6ff3eb0ce450") }Following is the query to display all documents from a collection with the help of find() method −> db.incrementDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cc81cdd8f9e6ff3eb0ce44e"), "PlayerScore" : 100 } { "_id" : ObjectId("5cc81ce28f9e6ff3eb0ce44f"), "PlayerScore" : 290 } { "_id" : ObjectId("5cc81ce68f9e6ff3eb0ce450"), "PlayerScore" : ... Read More

Template Specialization in C++

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

909 Views

In C++, the templates are used to create generalized functions and classes. So we can use any type of data like int, char, float, or some user defined data also using templates.In this section, we will see how to use the template specialization. So now we can define some generalized template for different types of data. And some special template function for special type of data. Let us see some example to get better idea.Example Code#include using namespace std; template void my_function(T x) {    cout

Add Components with a Relative Y Position in Java

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

156 Views

To add components with a relative Y position, use the GridBagConstraints.RELATIVE constant. Set this to gridy field −GridBagConstraints constraints = new GridBagConstraints(); constraints.gridy = GridBagConstraints.RELATIVE;The following is an example to add components with a relative Y position in Java −Examplepackage my; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame();       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       JPanel panel = new JPanel();       panel.setLayout(new GridBagLayout());       GridBagConstraints constraints = new GridBagConstraints();       constraints.gridx = ... Read More

Implement MySQL-like Statement in MongoDB

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

125 Views

To get MySQL LIKE statement, use the REGEX in MongoDB. Let us first create a collection with documents −> db.likeInMongoDBDemo.insertOne({"Name" : "Sam"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd6922857806ebf1256f123") } > db.likeInMongoDBDemo.insertOne({"Name" : "John" }); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd6923157806ebf1256f124") } > db.likeInMongoDBDemo.insertOne({"Name" : "Scott"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd6924557806ebf1256f125") } > db.likeInMongoDBDemo.insertOne({"Name" : "Sean"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd6924f57806ebf1256f126") } > db.likeInMongoDBDemo.insertOne({"Name" : "Samuel"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd6925857806ebf1256f127") }Following is the query to display all documents from a collection with ... Read More

HTML DOM Anchor Protocol Property

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

151 Views

The HTML DOM Anchor protocol property is used to set or return the protocol of a link in the href attribute.Following is the syntax to set the protocol property −anchorObj.protocol = protocol_urlAbove, protocol_url is the protocol of the URL. The values can be http, https, ftp, etc.Following is the syntax to return the protocol property −anchorObj.protocolLet us now see an example to implement the DOM Anchor protocol property −Example Live Demo Demo Heading Link = Services Display pathname Display hreflang Display port Display protocol function display1() { var ... Read More

HTML DOM Input Hidden Value Property

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

293 Views

The HTML DOM input hidden value property returns and modify the content of value attribute of input field of type=”hidden” in an HTML document.SyntaxFollowing is the syntax −1. Returning valueobject.value2. Modifying valueobject.value=”text”ExampleLet us see an example of HTML DOM input hidden value property − Live Demo    body{       text-align:center;       background-color:#F19A3E;       color:#fff;    }    .btn{       background-color:#3C787E;       border:none;       height:2rem;       border-radius:50px;       width:60%;       margin:1rem auto;       display:block;       color:#fff;   ... Read More

Advertisements