Find Device Power Connection Status in Android

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

416 Views

This example demonstrates How to find device power is connected 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 text view to show deice power status.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.annotation.SuppressLint; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; import android.os.BatteryManager; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.widget.TextView; import ... Read More

LocalDateTime plusDays Method in Java

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

310 Views

An immutable copy of a LocalDateTime object where some days are added to it can be obtained using the plusDays() method in the LocalDateTime class in Java. This method requires a single parameter i.e. the number of days to be added and it returns the LocalDateTime object with the added days.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalDateTime ldt = LocalDateTime.now();       System.out.println("The current LocalDateTime is: " + ldt);       System.out.println("The LocalDateTime with 10 days added is: ... Read More

DoubleStream mapToInt Method in Java

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

155 Views

The mapToInt() function of the DoubleStream class returns an IntStream consisting of the results of applying the given function to the elements of this stream.The syntax is as followsIntStream mapToInt(DoubleToIntFunction mapper)Here, mapper is a stateless function to apply to each element. The DoubleToIntFunction is a function that accepts a double-valued argument and produces an int-valued result.To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;The following is an example to implement DoubleStream mapToInt() method in JavaExample Live Demoimport java.util.stream.IntStream; import java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args) {       DoubleStream doubleStream = DoubleStream.of(45.8, ... Read More

Sum of Array Using Pointer Arithmetic in C

Nitya Raut
Updated on 30-Jul-2019 22:30:25

1K+ Views

In this program, we need to find sum of array elements using pointer arithmetic.Here we use * which denotes the value stored at the memory address and this address will remain stored in the variable. Thus “int *ptr” means, ptr is a variable which contains an address and content of the address is an integer quantity.*p means it is a pointer variable. Using this and sum() we will find out sum of the elements of array.Example Code#include  void s(int* a, int len) { int i, s_of_arr = 0; for (i = 0; i 

Fork in C

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

4K+ Views

In this section we will see what is the fork system call in C. This fork system call is used to create a new process. This newly created process is known as child process. The current process which is creating another child process is called the parent process.A child process uses the same program counter, CPU register, same files that are used by the parent process.The fork() does not take any parameter, it returns integer values. It may return three types of integer values.Negative Number: It returns negative number when child process creation is failedZero Value: It returns Zero for ... Read More

Use removeFirst in Android ConcurrentLinkedDeque

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

132 Views

Before getting into the example, we should know what ConcurrentLinkedDeque is, it is unbounded deque based on linked nodes. Multiple threads can access deque elements with safety.This example demonstrates about How to use removeFirst() in android ConcurrentLinkedDequeStep 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 a text view to show ConcurrentLinkedDeque elements.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.os.Build; import android.os.Bundle; ... Read More

Insert NULL Value in MySQL

Smita Kapse
Updated on 30-Jul-2019 22:30:25

3K+ Views

To insert a NULL value, you can use UPDATE command. Following is the syntax −UPDATE yourTableName SET yourColumnName=NULL;Let us first create a table −mysql> create table insertNullValue    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> ClientName varchar(100),    -> ClientCountryName varchar(20)    -> ); Query OK, 0 rows affected (0.54 sec)Following is the query to insert some records in the table using insert command −mysql> insert into insertNullValue(ClientName, ClientCountryName) values('Larry', 'US'); Query OK, 1 row affected (0.19 sec) mysql> insert into insertNullValue(ClientName, ClientCountryName) values('David', 'AUS'); Query OK, 1 row affected (0.09 sec) ... Read More

Get Tail Set from TreeSet in Java

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

95 Views

Let us first create a TreeSet and add elements to it:TreeSet treeSet = new TreeSet(); treeSet.add(20); treeSet.add(50); treeSet.add(100); treeSet.add(120); treeSet.add(150); treeSet.add(200); treeSet.add(250); treeSet.add(300); treeSet.add(350); treeSet.add(400);Now, let us get Tail Set from the TreeSet. In the below case, we will get elements above 200:SortedSet set = treeSet.tailSet(200);Exampleimport java.util.SortedSet; import java.util.TreeSet; public class Demo {    public static void main(String[] args) {       TreeSet treeSet = new TreeSet();       treeSet.add(20);       treeSet.add(50);       treeSet.add(100);       treeSet.add(120);       treeSet.add(150);       treeSet.add(200);       treeSet.add(250);       treeSet.add(300); ... Read More

Find Transitive Closure of a Graph in C++

Smita Kapse
Updated on 30-Jul-2019 22:30:25

517 Views

If a directed graph is given, determine if a vertex j is reachable from another vertex i for all vertex pairs (i, j) in the given graph. Reachable mean that there is a path from vertex i to j. This reachability matrix is called transitive closure of a graph. Warshall algorithm is commonly used to find the Transitive Closure of a Given Graph G. Here is a C++ program to implement this algorithm.AlgorithmBegin    1. Take maximum number of nodes as input.    2. For Label the nodes as a, b, c…..    3. To check if there any edge ... Read More

DoubleBuffer Put Method in Java

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

105 Views

The required value can be written at the current position of the buffer and then the current position is incremented using the method put() in the class java.nio.DoubleBuffer. This method requires a single parameter i.e. the value to be written in the buffer and it returns the buffer in which the value is inserted.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 {          DoubleBuffer buffer = DoubleBuffer.allocate(5);     ... Read More

Advertisements