Math.sqrt() Function in JavaScript

karthikeya Boyini
Updated on 25-Jun-2020 12:38:10

115 Views

The sqrt() function of the Math object accepts a number and returns the square root value of the given number.SyntaxIts Syntax is as followsMath.sqrt();Example Live Demo    JavaScript Example           var result = Math.sqrt(169);       document.write("Square root value of the given number: "+result);     OutputSquare root value of the given number: 13

Search Elements in a Sorted Object Array in Java

Arjun Thakur
Updated on 25-Jun-2020 12:38:00

215 Views

An element can be searched in a sorted object array in Java by using the methodjava.util.Arrays.binarySearch(). This method returns the index of the required element if it is available in the array, otherwise it returns (-(insertion point) - 1) where the insertion point is the position at which the element would be inserted into the array. A program that searches the required element in a sorted object array is given as follows −Example Live Demoimport java.util.Arrays; public class Demo {    public static void main(String[] args) {       String str[] = { "P", "M", "A", "T", "D"};     ... Read More

Math.trunc() Function in JavaScript

Samual Sam
Updated on 25-Jun-2020 12:37:50

131 Views

The trunc() function of the Math object accepts a number and returns its integral point (excluding the fractional part). If the given number itself is an integer this function returns the same.SyntaxIts Syntax is as followsMath.trunc();Example Live Demo    JavaScript Example           var result = Math.trunc(58.745);       document.write("Integral part of the given number: "+result);     OutputIntegral part of the given number: 58

Extend the Size of an Array in Java

Ankith Reddy
Updated on 25-Jun-2020 12:36:05

591 Views

An array has a fixed number of values and its size is defined when it is created. Therefore, the size of the array cannot be changed later. To solve this problem, an ArrayList should be used as it implements a resizable array using the List interface.A program that demonstrates ArrayList in Java is given as follows −Example Live Demoimport java.util.*; public class Demo {    public static void main(String args[]) {       ArrayList aList = new ArrayList();       aList.add("Apple");       aList.add("Melon");       aList.add("Orange");       aList.add("Mango");       aList.add("Grapes");     ... Read More

Modular Multiplicative Inverse in Java

Chandu yadav
Updated on 25-Jun-2020 12:35:39

975 Views

The java.math.BigInteger.modInverse(BigInteger m) returns a BigInteger whose value is (this-1 mod m). Using this method you can calculate Modular multiplicative inverse for a given number.ProgramLive Demoimport java.math.*; public class BigIntegerDemo {    public static void main(String[] args) {       // create 3 BigInteger objects       BigInteger bi1, bi2, bi3;             // create a BigInteger exponent       BigInteger exponent = new BigInteger("2");       bi1 = new BigInteger("7");       bi2 = new BigInteger("20");             // perform modPow operation on bi1 using bi2 and exp       bi3 = bi1.modPow(exponent, bi2);       String str = bi1 + "^" +exponent+ " mod " + bi2 + " is " +bi3;             // print bi3 value       System.out.println( str );    } }Output7^2 mod 20 is 9

Math Cosh Function in JavaScript

Samual Sam
Updated on 25-Jun-2020 12:35:37

67 Views

The cosh() function of the Math object accepts an angle (in radians) and returns its hyperbolic cosine value.SyntaxIts Syntax is as followsMath.cosh(90)Example Live Demo    JavaScript Example           var result = Math.cosh(90);       document.write("Hyperbolic cosine value of the given angle: "+result);     OutputHyperbolic cosine value of the given angle: 6.102016471589204e+38

Implement Binary Search on an Array in Java

George John
Updated on 25-Jun-2020 12:34:59

428 Views

Binary search can be implemented on an array by using the method java.util.Arrays.binarySearch(). This method returns the index of the required element if it is available in the array, otherwise it returns (- (insertion point) - 1) where the insertion point is the position at which the element would be inserted into the array.A program that demonstrates this is given as follows −Example Live Demoimport java.util.Arrays; public class Demo {    public static void main(String[] args) {       int arr[] = { 3, 9, 1, 6, 4};       Arrays.sort(arr);       System.out.print("The sorted array is: "); ... Read More

Math sinh Function in JavaScript

Samual Sam
Updated on 25-Jun-2020 12:34:10

81 Views

The sinh() function of the Math object accepts an angle (in radians) and returns its hyperbolic sine value.SyntaxIts Syntax is as followsMath.sinh(90)Example Live Demo    JavaScript Example           var result = Math.sinh(90);       document.write("Hyperbolic sine value of the given angle: "+result);     OutputHyperbolic sine value of the given angle: 6.102016471589204e+38

Modular Exponentiation Power in Modular Arithmetic in Java

George John
Updated on 25-Jun-2020 12:34:08

1K+ Views

The java.math.BigInteger.modPow(BigInteger exponent, BigInteger m) returns a BigInteger whose value is (thisexponent mod m). Unlike pow, this method permits negative exponents. You can calculate the modular Exponentiation using this method.ProgramLive Demoimport java.math.*; public class BigIntegerDemo {    public static void main(String[] args) {       // create 3 BigInteger objects       BigInteger bi1, bi2, bi3;             // create a BigInteger exponent       BigInteger exponent = new BigInteger("2");       bi1 = new BigInteger("7");       bi2 = new BigInteger("20");             // perform ... Read More

Schedule Tasks in Java for Fixed Rate Execution

Anvi Jain
Updated on 25-Jun-2020 12:33:59

2K+ Views

One of the methods the Timer class is void scheduleAtFixedRate(TimerTask task, Date firstTime, long period). This method schedules the specified task for repeated fixed-rate execution, beginning at the specified time.In fixed-rate execution, each execution is scheduled with respect to the scheduled run time of the initial execution. Fixed-rate execution is apt for repetitive activities that are respond to absolute time. Likewise, fixed-rate execution is appropriate for scheduling multiple repeating timer tasks that must remain in sync.Declaration − The java.util.Time.scheduleAtFixedRate(TimerTask task, Date firstTime, long period) method is declared as follows −public void scheduleAtFixedRate(TimerTask task, Date firstTime, long period)Here, task is the ... Read More

Advertisements