Here we will see one data-structure with n elements, and O(1) operations. So the operations will take constant amount of time to execute.The data structure will hold n elements (from 0 to n-1). The data can be in any order. The Insertion, deletion and searching will take O(1) amount of time.To solve this problem, we will use one Boolean array. This will indicate that the item is present or not at position i. If the item is present, it will hold 1, otherwise 0.Algorithminitialization(n)begin fill all elements of the Boolean array as 0 endinsert(i)begin set element at index ... Read More
Given with two numbers x and y the output should contain their kth common factor.Input: x=9 y=18 k=1 Output : k common factor = 2 Factors of 9 : 1, 3, 9 Factors of 18 : 1, 2, 3, 6, 9, 18 Greatest Common Factor : 9AlgorithmSTART Step 1 -: take input as x and y lets say 3 and 21 and k as 1 Step 2 -: declare start variables as int i,num,count=1 Step 3 -: IF x
The following is an example to change JButton font dynamically:Exampleimport java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; public class SwingDemo extends JFrame { JButton button = new JButton("Change"); int fontSize = 10; public SwingDemo() { setSize(500, 400); setDefaultCloseOperation(EXIT_ON_CLOSE); add(button); // changing font size dynamically on button click button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { button.setFont(new Font("Dialog", Font.PLAIN, ++fontSize)); button.revalidate(); } }); setVisible(true); } public static void main(String[] args) { new SwingDemo(); } }OutputClick “Change” button above to change the font:
This example demonstrate about Start an Activity from a Notification 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 the following code to src/MainActivity.javapackage app.tutorialspoint.com.notifyme ; import android.app.NotificationChannel ; import android.app.NotificationManager ; import android.app.PendingIntent ; import android.content.Context ; import android.content.Intent ; import android.support.v4.app.NotificationCompat ; import android.support.v7.app.AppCompatActivity ; import android.os.Bundle ; import android.view.View ; import android.widget.Button ; public class MainActivity extends AppCompatActivity { public static final String ... Read More
The difference between '==' and '===' is that former checks only value but the latter checks value and also data type(String, Boolean etc).The following example gives whether values assigned are equal or not irrespective of datatype. a) "==" operator(checks equality) Example Live Demo var x = 5; var y = 5; var z = 6; document.getElementById("strict").innerHTML = (x == y) + "" + (x == z); Outputtrue falseb) '===' operator (Checks strict equality) "===" operator gives true if and only if both value and data type are equal.If not it returns false.In ... Read More
In this program we will count the number of ways one number can be represented by sum of numbers smaller than itself. This program will count the partition of given numbers. We take a number n as input, then starting from a number break it by removing 1 at a time. If the new partition is generated, increase the counter.AlgorithmpartitionCount(n)Input : The number nOutput : The number of partitionsBegin Create array p of size n k := 0 count := -1 put n as the first element of array p Repeat the following steps, do ... Read More
To perform SELECT with COUNT, use aggregate function COUNT(). Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(100), Subject varchar(100) ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name, Subject) values('John', 'MySQL'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(Name, Subject) values('John', 'Java'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(Name, Subject) values('Carol', 'MongoDB'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(Name, Subject) values('Carol', ... Read More
Text modeBinary modeIn text mode various character translations are performed i.e;“\r+\f” is converted into “”In binary mode, such translations are not performed.To write in the files:ofstream ofs (“file.txt”);Orofstream ofs;ofs.open(“file.txt”);to write in the files: ofstream ofs(“file.txt”, ios::binary);orofstream ofs;ofs.open(“file.txt”, ios::binary);To add text at the end of the file:Ofstream ofs(“file.txt”, ios::app);orofstream ofs;ofs.open(“file.txt”, ios::app);To add text at the end of the file:Ofstreamofs(“file.txt”, ios::app|ios::binary);or ofstream ofs;ofs.open(“file.txt”, ios::app|ios::binary);To read files:ifstream in (“file.txt”);orifstreamin ; in.open(“file.txt”);To read files: ifstream in (“file.txt”, ios::binary);orifstream in ;in.open(“file.txt”, ios::binary);Read More
The HTML DOM input image Object represent the element with type=”image” of an HTML document.Let’s see how to create input image object −SyntaxFollowing is the syntax −var imageInput = document.createElement(“INPUT”); imageInput.setAttribute(“type”, ”image”);PropertiesFollowing are the properties of HTML DOM input image Object −PropertyExplanationAltIt returns and modify the value of the alt attribute of an input image.AutofocusIt returns whether the browser finished loading an image in HTML web page or not.defaultValueIt returns and modify the default value of an input image.DisabledIt returns and modify the value of the disabled attribute of an input image.FormIt returns the reference of the form that ... Read More
Here we will see one interesting problem related to array. There is an array with n elements. We have to create another array of n elements. But the i-th position of second array will hold the product of all elements of the first array except the i-th element. And one constraint is that we cannot use the division operator in this problem. We have to solve this problem in-place without using any additional spaces.If we can use the division, operation, we can easily solve this problem, by getting the product of all elements, then divide i-th element of first array ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP