Following is a Java program which prints a pyramid of numbers.Example Live Demopublic class PrintingPyramidStars { public static void main(String args[]){ int n,i,j; n = 5; for(i = 0; i
Here we will see about the argument coercion in C or C++. The Argument Coercion is one technique by which the compiler can implicitly convert the arguments from one type to another type. It follows argument promotion rule. If one argument is lower datatype, that can be converted into higher datatypes, but the reverse is not true. The reason is if one higher datatype is converted into a lower datatype, it may loss some data.Let us see one pyramid that can express how the implicit conversion takes place.Example Live Demo#include using namespace std; double myAdd(double a, double b){ return a+b; ... Read More
In this post, we are going to learn, how to detect lines in an image, with the help of a technique called Hough transform.Hough transform?Hough transform is a feature extraction method to detect any simple shape, if you can represent that shape in mathematical form. It somehow manage to detect the shape even if it is broken or distorted a little bit. We will see how it works for a line.A “simple” shape is one that can be represented by only a few parameters. For example, a line can be represented by two parameters only (slope, intercept) and a circle ... Read More
MODELESS TypeThe following is an example to set JDialog with Modality type MODELESS −Exampleimport java.awt.Cursor; import java.awt.Dialog.ModalityType; import java.awt.Dimension; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFrame; public class SwingDemo { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(new Dimension(600, 400)); JDialog dialog = new JDialog(frame, "New", ModalityType.MODELESS); dialog.setSize(300, 300); frame.add(new JButton(new AbstractAction("Click to generate") { @Override public void actionPerformed(ActionEvent e) { frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); ... Read More
This example demonstrate about How can I insert an EditText (for inserting text) on an Android notificationStep 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 res/layout/custom_notification_layout.xml. Step 4 − Add the following code to src/MainActivity.package app.tutorialspoint.com.notifyme ; import android.app.NotificationChannel ; import android.app.NotificationManager ; import android.os.Bundle ; import android.support.v4.app.NotificationCompat ; import android.support.v7.app.AppCompatActivity ; import android.view.View ; import android.widget.RemoteViews ; ... Read More
To update array in MongoDB document by variable index, use the below syntax. Here, yourIndexValue in the index value, where yourIndexVariableName is the variable name for index −var yourIndexVariableName= yourIndexValue, anyVariableName= { "$set": {} }; yourVariableName["$set"]["yourFieldName."+yourIndexVariableName] = "yourValue"; db.yourCollectionName.update({ "_id": yourObjectId}, yourVariableName);Let us first create a collection with documents −> db.updateByVariableDemo.insertOne({"StudentSubjects":["MySQL", "Java", "SQL Server", "PL/SQL"]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd553c37924bb85b3f4893a") }Following is the query to display all documents from a collection with the help of find() method −> db.updateByVariableDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cd553c37924bb85b3f4893a"), "StudentSubjects" : [ ... Read More
To get the total number of leaved of a JTree, apply the getLeafCount() method on the root node. Let’s say our root node is “node”, therefore to count the number of leaves, use −node.getLeafCount()The following is an example to get the total number of leaves of a JTree −package my; import javax.swing.JFrame; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; public class SwingDemo { public static void main(String[] args) throws Exception { JFrame frame = new JFrame("Demo"); DefaultMutableTreeNode node = new DefaultMutableTreeNode("Website"); DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("Videos"); DefaultMutableTreeNode node2 = new ... Read More
To enable multiple selections in a JFileChooser dialog, use the setMultiSelectionEnabled() to be TRUE −JFileChooser file = new JFileChooser(); file.setMultiSelectionEnabled(true);The following is an example to enable multiple selections in a JFileChooser Dialog −Examplepackage my; import javax.swing.JFileChooser; public class SwingDemo { public static void main(String[] args) { JFileChooser file = new JFileChooser(); file.setMultiSelectionEnabled(true); file.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); file.setFileHidingEnabled(false); if (file.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { java.io.File f = file.getSelectedFile(); System.err.println(f.getPath()); } } }Output
To limit number of values in a field, use $slice operator.Let us first create a collection with documents −> db.numberOfValuesDemo.insertOne({"Values":[100,200,300,900,1000,98]}); { "acknowledged" : true, "insertedId" : ObjectId("5cefb736ef71edecf6a1f6ab") }Display all documents from a collection with the help of find() method −> db.numberOfValuesDemo.find().pretty();Output{ "_id" : ObjectId("5cefb736ef71edecf6a1f6ab"), "Values" : [ 100, 200, 300, 900, 1000, 98 ] }Following is the query to limit number of values in a field using MongoDB −> db.numberOfValuesDemo.find({},{ "Values": { "$slice": 2 } } );Output{ "_id" : ObjectId("5cefb736ef71edecf6a1f6ab"), "Values" : [ 100, 200 ] }
Whenever, we instantiate and use certain objects/resources we should close them explicitly else there is a chance of Resource leak.Generally, we used close resources using the finally block as −Connection con = null; Statement stmt = null; ResultSet rs = null; //Registering the Driver try { con = DriverManager.getConnection(mysqlUrl, "root", "password"); stmt = con.createStatement(); } catch (SQLException e) { e.printStackTrace(); } finally { try { rs.close(); stmt.close(); con.close(); } catch(SQLException e) { e.printStackTrace(); } }From JSE7 onwards the try-with-resources statement is ... Read More