Calculate Possibilities of Duplication for Random Number in Java

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

191 Views

To get the duplicate numbers for random numbers in a range, loop through and create two Random class objects −Use nextInt() to get the next number −intrandVal1 = new Random().nextInt(50); intrandVal2 = new Random().nextInt(50);Now, compare both the above numbers −if (randVal1 == randVal2) {    System.out.println("Duplicate number = "+randVal1); }All the above is to be done in a loop −for (int i = 1; i

Add Multiple Records in a Single MySQL Query

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

180 Views

You can easily add multiple items with only one insert command. The syntax is as follows −insert into yourTableName(yourColumnName1, yourColumnName2, ......N) values(yourValue1, yourValue2, ....N), (yourValue1, yourValue2, ....N), ..........N;Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Value1 int,    Value2 int,    Value3 int ); Query OK, 0 rows affected (0.79 sec)Insert multiple records in the table using insert command −mysql> insert into DemoTable(Value1, Value2, Value3) values(10, 20, 40), (100, 148, 120), (150, 670, 1000), (100000, 200000, 409999); Query OK, 4 rows affected (0.17 sec) Records : 4 Duplicates : ... Read More

Handle Action Event for JComboBox in Java

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

827 Views

The following is an example to handle action event for JComboBox in Java:Exampleimport java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; public class SwingDemo {    public static void main(String[] args) throws Exception {       JFrame frame = new JFrame();       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       JComboBox combo = new JComboBox(new String[] { "One", "Two", "Three", "Four", "Five", "Six" });       JButton add = new JButton("Add");       add.addActionListener(new ActionListener() {          @Override          public void actionPerformed(ActionEvent e) {             ... Read More

Operation on Two BCD Numbers Based on Contents of X in 8085

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

139 Views

Now let us see a program of Intel 8085 Microprocessor. In this program we will see how to do different operations on BCD numbers based on choice.Problem Statement:Write 8085 Assembly language program to perform some operations on two 8-bit BCD numbers base on choice.Discussion:In this program we are taking a choice. The choice value is stored at memory location 8000H (named as X). And the BCD numbers are stored at location 8001H and 8002H. We are storing the result at location 8050H and 8051H.Here if the choice is 00H, then it will perform addition, for 01H, it will perform subtraction, ... Read More

ByteBuffer allocateDirect Method in Java

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

338 Views

A direct byte buffer can be allocated using the method allocateDirect() in the class java.nio.ByteBuffer. This method requires a single parameter i.e. the capacity in bytes and it returns the direct byte buffer. If the capacity provided is negative, then the IllegalArgumentException is thrown.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          ByteBuffer buffer = ByteBuffer.allocateDirect(n);          byte[] byteValues = { 7, 1, 6, 3, ... Read More

Filter Array in Subdocument with MongoDB

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

418 Views

You can use aggregate and unwind the array list before applying match. To understand the above concept, let us create a collection with documents. The query to create a collection with document is as follows:> db.filterArray.insertOne( { "L": [{ "N":1 }, { "N":2 } , { "N":3 }, { "N":4 }, { "N":5 } ]});The following is visible after running the above query:{    "acknowledged" : true,    "insertedId" : ObjectId("5c6d63f2734e98fc0a434aeb") }Display document from a collection with the help of find() method. The query is as follows:> db.filterArray.find().pretty();The following is the output:{    "_id" : ObjectId("5c6d63f2734e98fc0a434aeb"),    "L" : [ ... Read More

What is a Request Object in JSP

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

1K+ Views

The request object is an instance of a javax.servlet.http.HttpServletRequest object. Each time a client requests a page, the JSP engine creates a new object to represent that request.The request object provides methods to get HTTP header information including form data, cookies, HTTP methods, etc.Following is the example which uses getHeaderNames() method of HttpServletRequest to read the HTTP header information. This method returns an Enumeration that contains the header information associated with the current HTTP request.Once we have an Enumeration, we can loop down the Enumeration in the standard manner. We will use the hasMoreElements() method to determine when to stop ... Read More

Get Full Screen Activity in Android

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

4K+ Views

This example demonstrate about How to get full screen activity in android.Step 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 the digital clock view to show a clock.Step 3− Add the following code to java/MainActivity.xmlpackage com.example.myapplication; import android.annotation.TargetApi; import android.content.pm.ActivityInfo; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.view.Window; import android.view.WindowManager; public class MainActivity extends AppCompatActivity {    @TargetApi(Build.VERSION_CODES.LOLLIPOP)   ... Read More

LocalTime compareTo Method in Java

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

2K+ Views

Two LocalTime objects can be compared using the compareTo() method in the LocalTime class in Java. This method requires a single parameter i.e. the LocalTime object to be compared.If the first LocalTime object is greater than the second LocalTime object it returns a positive number, if the first LocalTime object is lesser than the second LocalTime object it returns a negative number and if both the LocalTime objects are equal it returns zero.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Main{    public static void main(String[] args){       LocalTime lt1 = LocalTime.parse("11:37:12");   ... Read More

LongStream count Method in Java

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

136 Views

The count() method of the LongStream class in Java is used to return the count of elements in this stream.The syntax is as follows.long count()To use the LongStream class in Java, import the following package.import java.util.stream.LongStream;Create a LongStream and add some elements.LongStream longStream = LongStream.of(50L, 30L, 80L, 40L, 15L, 60L);Now, get the count of elements.longStream.count()The following is an example to implement LongStream count() method in Java.Example Live Demoimport java.util.stream.LongStream; public class Demo {    public static void main(String[] args) {       LongStream longStream = LongStream.of(50L, 30L, 80L, 40L, 15L, 60L);       System.out.println("The number of elements in the ... Read More

Advertisements