## Java Program to calculate the area of a triangle using Heron's Formula

Heron’s formula gives the area of a triangle when the length of all three sides are already known.Let’s say we have the following three sides of a triangle −s1 = 15191235.0; s2 = 15191235.0; s3 = 1.01235479;Now, use the Heron’s formulae to find the area −area = (s1+s2+s3)/2.0d; resArea = ... Read More

## How to convert Integer array list to integer array in Java?

To convert integer array list to integer array is not a tedious task. First, create an integer array list and add some elements to it −ArrayList < Integer > arrList = new ArrayList < Integer > (); arrList.add(100); arrList.add(200); arrList.add(300); arrList.add(400); arrList.add(500);Now, assign each value of the integer array list ... Read More

## Java Program to get prime numbers using the Sieve of Eratosthenes algorithm

To find all prime numbers up to any given limit, use the Sieve of Eratosthenes algorithm. At first we have set the value to be checked −int val = 30;Now, we have taken a boolean array with a length one more than the val −boolean[] isprime = new boolean[val + ... Read More

## Java Program to create a Calculator

To create a calculator with Java Swings, try the following code −Exampleimport java.awt.Color; import java.awt.Container; import java.awt.FlowLayout; import javax.swing.JFrame; import javax.swing.JLabel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JTextField; public class SwingDemo extends JFrame implements ActionListener {    JButton one, two, three, four, five, six, seven, eight, nine, num0, ... Read More

## Java Program to save decimal

Let’s say the value is 0.10705921712947473 and you want to save only the first 3 decimal digits. At first let us declare the values −double val = 320.0 / 2989.0; BigDecimal big = new BigDecimal(val);Now, use setScale() and set the parameter as 3 to save 3 decimal places −big = ... Read More

## Java Program to evaluate mathematical expressions in String

To evaluate mathematical expression in String, use Nashorn JavaScript in Java i.e. scripting. Nashorn invoke dynamics feature, introduced in Java 7 to improve performance.For scripting, use the ScriptEngineManager class for the engine −ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); ScriptEngine scriptEngine = scriptEngineManager.getEngineByName("JavaScript");Now for JavaScript code from string, use eval i.e. execute ... Read More

## How do you hide the onscreen keyboard in iOS App?

To hide a keyboard on screen we need to make use of some internal functions that are predefined in the iOS SDK. The keyboard appears on screen when we are typing in a text Field or textView. We need to make use of internal function according to the text field.For ... Read More

## How to resize an UIImageView using Swift?

To resize an image in iOS using swift we’ll make use of frame.Let’s see this with help of an example.Create an empty project and add an empty Image view.Create its outlet.Add an image to your project and assign the image to image view.Initially when we run the application, it looks ... Read More

## How do I load an image by URL on iOS device using Swift?

To load an image in iOS using swift we’ll make use of simple data Task session. The image needs to be loaded in background because it may be of any size and we don’t want it to stop our main view’s operations.Let’s see this with help of an example. Create ... Read More

## How to make an HTTP POST request on iOS App using Swift?

To make an http request in iOS we’ll make use of DataTask and sessions. We’ll create configuration, sessions, url, request, and dataTask objects. Let’s see the steps that we’ll go through.First of all we need to create a session object, which default configuration.let configuration = URLSessionConfiguration.default let session = URLSession(configuration: ... Read More

## How to check Location Manager is running or not in iOS App?

To check any services related to location in ios with swift we can use the CLLocationManager.In this example we’ll see how to check if the location manager is running or not. We’ll do this with help of an sample project. So, create a new project. First we need to create ... Read More

## Getting a distinct aggregation of an array field across indexes

To get a distinct aggregation of an array field across indexes, let us take an example and create a collection with some documents.Following is the query to create a collection with documents> db.distinctAggregation.insertOne({"UserName":"Larry", "UserPost":["Hi", "Hello"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c98aefb330fd0aa0d2fe4c6") } > db.distinctAggregation.insertOne({"UserName":"Chris", "UserPost":["Hi", "Good Morning"]}); ... Read More