Add a Value in Octet Tuple in Java

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

107 Views

To add value in Octet Tuple, you need to use the addAtX() method. Here, X is the index wherein you need to add the value i.e. to add value at index 0, use the addAt0() and value as a parameter.Let us first see what we need to work with JavaTuples. To work with Octet class in JavaTuples, you need to import the following package −import org.javatuples.Octet;Note − Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project -> Properties -> Java Build Path -> Add External Jars and upload the downloaded JavaTuples ... Read More

Auto Increment in MongoDB for Unique User ID

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

947 Views

To auto increment in MongoDB to store a sequence of unique user id, let us create a collection which contains information about last sequence values of all documents.Let us first create a collection. The query to create a collection which is as follows −> db.createSequenceDemo.insertOne({_id:"SID", S_Value:0}); { "acknowledged" : true, "insertedId" : "SID" }Now, we will create a function that will generate an auto increment in MongoDB to store sequence. The query is as follows −> function nextSequence(s) {    ... var sd = db.createSequenceDemo.findAndModify({       ... query:{_id: s },       ... update: {$inc:{S_Value:1}},     ... Read More

Stop MySQL Decimal Field from Being Rounded

George John
Updated on 30-Jul-2019 22:30:25

587 Views

You can stop rounding decimal field with the help of DECIMAL() function. Here is the demo of a rounded decimal field. For our example, let us first create a demo tablemysql> create table stopRoundingDemo    -> (    -> Amount DECIMAL(7)    -> ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into stopRoundingDemo values(7836.783); Query OK, 1 row affected, 1 warning (0.43 sec) mysql> insert into stopRoundingDemo values(1737.67); Query OK, 1 row affected, 1 warning (0.23 sec) mysql> insert into stopRoundingDemo values(110.50); Query OK, 1 ... Read More

Tellp in File Handling with C++

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

2K+ Views

In C++ file handling, the tellp() function is used with output streams, and returns the current put position of the pointer in the stream. It returns an integer data type, representing the current position of the stream pointer.tellp() method takes no parameter. It is written as: pos_type tellp();AlgorithmBegin.    Create an object newfile against the class fstream.    Call open() method to open a file “tpoint.txt” to perform write operation using object newfile.    Insert data into the file object newfile.    Call the tellp() method to print the present position of the pointer in the file object.    Call ... Read More

Make a Call in Android

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

271 Views

This example demonstrate about How to make a call 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.     In the above code, we have taken list view.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.annotation.TargetApi; import android.app.Activity; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.database.Cursor; import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.provider.ContactsContract; import android.support.annotation.NonNull; import android.support.v4.app.ActivityCompat; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import ... Read More

Generate Random Elements from a Given Array in Java

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

505 Views

Let’s say the following is our array −Integer[] arr = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20};Now, we can convert it to a list before shuffling it −Listlist = Arrays.asList(arr); Collections.shuffle(list);The above shuffling generates random elements. Display them like this −for (Integer res: list) {    System.out.print(res + " "); }Example Live Demoimport java.util.Arrays; import java.util.Collections; import java.util.List; public class Demo {    public static void main(String[] args) {       Integer[] arr = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20};       System.out.print("Array elements...");       for (Integer res: arr) { ... Read More

Assign Multiple Characters in an Int in C Language

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

362 Views

The character type data is stored by its ASCII value internally in C or C++. If we want to print a single character as integer, we will get the ASCII value. But when we are trying to print more than one character using a single quote, then it will print some strange output.Please check the following program to get the idea.Example#include int main() {    printf("%d", 'A');    printf("%d", 'AA');    printf("%d", 'ABC'); }Output65 16705 4276803The ASCII of A is 65. So at first it is showing 65 (01000001). Now for AA, it is showing 16705. This is ASCII ... Read More

Command Line and Variable Arguments in Python

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

632 Views

Command Line ArgumentsCommand line arguments are input parameters which allow user to enable programs to act in a certain way like- to output additional information, or to read data from a specified source or to interpret the data in a desired format.Python Command Line ArgumentsPython provides many options to read command line arguments. The most common ways are -Python sys.argvPython getopt modulePython argparse modulePython sys moduleThe sys module stores the command line arguments (CLA) into a list and to retrieve it, we use sys.argv. It’s a simple way to read command line arguments as string.import sys print(type(sys.argv)) print('The command ... Read More

Interface 8255 with 8085 Microprocessor for Addition

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

1K+ Views

In this program we will see how to perform addition by using ports to take data and send the result into the port.Problem StatementWrite 8085 Assembly language program for interfacing between 8085 and 8255. Here Port A and Port B are holding two values, take the numbers from port A and B, add them, and send the result at port C.DiscussionThe task is very simple. At first we have to setup the control word register of 8255 chip. After that we will take the input from port A and B, add the content, and send it to port C.The control ... Read More

Store HashMap in Singleton in Android

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

347 Views

Before getting into an example, we should know what singleton design pattern is. A singleton is a design pattern that restricts the instantiation of a class to only one instance. Notable uses include controlling concurrency and creating a central point of access for an application to access its data store.This example demonstrates How to store Hashmap in Singleton 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. In the ... Read More

Advertisements