Found 7442 Articles for Java

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

Multiplicative order in java

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

145 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

Multiplicative order in java

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

145 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

Modular multiplicative inverse in java

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

948 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

Modular multiplicative inverse in java

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

948 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

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

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

Nth Catalan numbers in java

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

242 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

Nth Catalan numbers in java

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

242 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

Catalan numbers in java

Arjun Thakur
Updated on 25-Jun-2020 12:25:10

725 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 CatalanNumbers {    public static long fact(int i) {       if(i

Advertisements