Binomial Coefficient in Java

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

5K+ Views

Binomial coefficient (c(n, r) or nCr) is calculated using the formula n!/r!*(n-r)!. Following is the Java program find out the binomial coefficient of given integers.Programimport java.util.Scanner; public class BinomialCoefficient {    public static long fact(int i) {       if(i

Sort Subset of Array Elements in Java

George John
Updated on 25-Jun-2020 12:41:05

5K+ Views

The java.util.Arrays.sort() method can be used to sort a subset of the array elements in Java. This method has three arguments i.e. the array to be sorted, the index of the first element of the subset (included in the sorted elements) and the index of the last element of the subset (excluded from the sorted elements). Also, the Arrays.sort() method does not return any value.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[] = { 1, 9, 7, 3, 2, 8, ... Read More

Number.isFinite Function in JavaScript

Samual Sam
Updated on 25-Jun-2020 12:40:36

95 Views

The isFinite() function of the Number object accepts a number and determines if it is finite number. If the given number is finite it returns true else, it returns false.SyntaxIts Syntax is as followsNumber.isFinite(100/0);Example Live Demo    JavaScript Example           var result1 = Math.min();       document.write(isFinite(result1));       document.write("");       var result2 = Number.isFinite(100/0);       document.write(result2);       document.write("");       var result3 = Math.max(25, 36, 862);       document.write(isFinite(result3));       document.write("");       document.write(isFinite("Hello"));     Outputfalse false true false

Number.isInteger Function in JavaScript

karthikeya Boyini
Updated on 25-Jun-2020 12:40:01

114 Views

The isInteger() function of the Number object accepts a number and determines if it is finite number. If the given number is finite it returns true else, it returns false.SyntaxIts Syntax is as followsNumber.isInteger(100/0);Example Live Demo    JavaScript Example           var result = Number.isFinite(100/0);       if(result) {          document.write("Given number is finite");       }else {          document.write("Given number is infinite");       }     OutputGiven number is infiniteExampleIn addition to equation you can also pass positive number, negative number, zero and ... Read More

Multiplicative Order in Java

Arjun Thakur
Updated on 25-Jun-2020 12:39:40

164 Views

Following is a Java program which prints the multiplicative order of given numbers.import java.util.Scanner;Programpublic class MultiplicativeOrder {    public static int gcd(int num1, int num2) {       if (num2 != 0) {          return gcd(num2, num1 % num2);       } else {          return num1;       }    }    static int multiplicativeOrder(int num1, int num2) {       if (gcd(num1, num2) != 1) {          return -1;       }       int res = 1;       int p ... Read More

Sort Arrays of Objects in Java

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

545 Views

An array of objects can be sorted using the java.util.Arrays.sort() method with a single argument required i.e. the array to be sorted. A program that demonstrates this is given as follows −Example Live Demoimport java.util.Arrays; public class Demo {    public static void main(String args[]) throws Exception {       String str[] = new String[]{"apple", "orange", "mango", "guava", "melon"};       int n = str.length;       System.out.println("The original array of strings is: ");       for (int i = 0; i < n; i++) {          System.out.println(str[i]);       }     ... Read More

Math.round() Function in JavaScript

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

174 Views

The round() function of the Math object accepts a floating point random number and returns its nearest integer value.If the given number is x.5 or more this function returns the next number (x+1)If the given number is x.4 or less this function returns the previous number (x-1).If the given number itself is an integer this function returns the same.SyntaxIts Syntax is as followsMath.round();Example Live Demo    JavaScript Example           var result = Math.round(2541.542);       document.write("Rounded value of the given number: "+result);     OutputRounded value of the given number: 2542

Math.sign() Function in JavaScript

Samual Sam
Updated on 25-Jun-2020 12:38:31

124 Views

The sign() function of the Math object accepts an integer number and returns its sign.(positive, negative)If the given number is a positive integer then, this function returns +1.And, if the given number is a negative integer then, this function returns -1.SyntaxIts Syntax is as followsMath.sign();Example Live Demo    JavaScript Example           var result = Math.sign(-128);       document.write("Result: "+result);     OutputResult: -1

Math.sqrt() Function in JavaScript

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

125 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

230 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

Advertisements