Here we will see some good tricks of C++ programming language that can help us in different area. Like if we want to participate in some competitive programming events, then these tricks will help us to reduce the time for writing codes. Let us see some of these examples one by one.Checking whether a number is odd or even without using % operator. This trick is simple. We can perform bitwise AND operation with the number and 1. If the result is non-zero then this is odd, otherwise this is even. The logic is too simple. All odd numbers have ... Read More
Let us first create and array and add elements −String[] sports = { "Football", "Cricket", "Squash", "Baseball", "Fencing", "Volleyball", "Basketball" };Now, set the above array elements to the JOptionPane −String res = (String) JOptionPane.showInputDialog(null, "Which sports you play the most?", "Sports", JOptionPane.PLAIN_MESSAGE, null, sports, sports[0]);Above, we have also set the initial value i.e. sports(0).The following is an example to use JOptionPane with array elements in Java −Examplepackage my; import javax.swing.JOptionPane; public class SwingDemo { public static void main(String[] args) { String[] sports = { "Football", "Cricket", "Squash", "Baseball", "Fencing", "Volleyball", "Basketball" }; ... Read More
You can use $addToSet operator for this. Let us first create a collection with documents −> db.insertDataIntoArrayDemo.insertOne( { "UserDetails":[ { "UserId" :"user121", "userGroupMessage":[] }, { "UserId" :"user221", "userGroupMessage":["Cool", "Good Morning"] } ] } ); { "acknowledged" : true, "insertedId" : ObjectId("5cd694e157806ebf1256f128") }Following is the query to display all documents from ... Read More
Classic Ethernet is the original form of Ethernet used primarily in LANs. It provides data rates between 3 to 10 Mbps.It operates both in the physical layer and in the MAC sublayer of the OSI model. In the physical layer, the features of the cables and networks are considered. In MAC sublayer, the frame formats for the Ethernet data frame are laid down.Classic Ethernet was first standardized in 1980s as IEEE 802.3 standard.Frame Format of Classic EthernetClassic Ethernet frames can be either of Ethernet (DIX) or of IEEE 802.3 standard. The frames of the two standards are very similar except ... Read More
The HTML DOM input month defaultValue property returns and modify the default value of input field of type=”month” in a HTML document.SyntaxFollowing is the syntax −1. Returning default valueobject.defaultValue2. Modifying default valueobject.defaultValue=valueHere, value is any date in form of string for example “2019-03”ExampleLet us see an example of HTML DOM input month defaultValue property − Live Demo html{ height:100%; } body{ text-align:center; color:#fff; background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) center/cover no-repeat; height:100%; } p{ ... Read More
Given with equation program must find the value of ‘a’ where a+b Declare start variables b=10, x=9, n=40 and flag=0, divisible Step 2 -> Loop For divisible = (b / x + 1 ) * x and divisible = 1 Print divisible-1 Set flag=1 End END STOPExample#include int main(int argc, char const *argv[]) { int b=10, x=9, n=40, flag = 0; int divisible; for (divisible = (b / x + 1 ) * x ; divisible = 1) { printf("%d ", divisible - b ); flag = 1; } } return 0; }Outputif we run above program then it will generate following output8 17 26
The following is an example to get or set the selection state of JCheckBox:Exampleimport java.awt.FlowLayout; import javax.swing.JCheckBox; import javax.swing.JFrame; public class SwingDemo extends JFrame { public SwingDemo() { setSize(500, 500); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new FlowLayout(FlowLayout.CENTER)); JCheckBox checkBox = new JCheckBox("Demo"); checkBox.setSelected(true); boolean sel = checkBox.isSelected(); if (sel) System.out.println("Check box selected!"); getContentPane().add(checkBox); } public static void main(String[] args) { new SwingDemo().setVisible(true); } }OutputSince the checkbox is selected by default, the following output would be visible in EclipseIDE:
The supportsTransactions() method of the DatabaseMetaData interface is used to determine whether the underlying database supports transactions.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 user ... Read More
The use of "=" operator is that it assigns value from right to left, whereas "==" shows whether the given values are equal or not.In the following example variables x and y were assigned values using "=" operator and their magnitudes were checked using "==" operator.Example Live Demo var x = 5; var y = "6"; document.write(x); document.getElementById("equal").innerHTML = (x == y); Outputfalse 5
In C++, there are some undefined behaviors. These are identified by doing some tasks in C++. There are no such direct definitions. These few things should be known to all of the programmers, who want to use C++ for different purposes.Here we will see some C++ Codes. and try to guess the results. The codes will generate some runtime errors.The Divide By Zero error is undefined.Example Code#include using namespace std; int main() { int x = 10, y = 0; int z = x / y; cout
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP