Math.trunc() Function in JavaScript

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

162 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

610 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

1K+ 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

75 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

451 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

105 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

Math.fround() Function in JavaScript

Samual Sam
Updated on 25-Jun-2020 12:33:05

266 Views

The fround() function of the Math object accepts a floating point number and returns the nearest 32-bit single precision float representation of a Number. If the given number itself is an integer this function returns the same.SyntaxIts Syntax is as followsMath.fround(160.98)Example Live Demo    JavaScript Example           var result = Math.fround(160.98);       document.write("Fround value: "+result);     OutputFround value: 160.97999572753906

Nth Catalan Numbers in Java

Ankith Reddy
Updated on 25-Jun-2020 12:32:38

277 Views

The nth Catalan number in terms of binomial coefficients is calculated by the formula(n + k )/k where k varies from 2 to n and n ≥ 0. i.e.Cn = (2n)!/((n+1)!n!)Programpublic class NthCatalanNumber {    public static long fact(int i) {       if(i

Advertisements