- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 272 Articles for Java8
3K+ 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
83 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
574 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
660 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
945 Views
A composite number whose sum of digits equal to the sum of the digits of its prime factors.Ex: 58 = 2 x 29 (5 + 8 = 12) (2+ 2 + 9 = 12)Programpublic class SmithNumbers { public static boolean isPrime(int number) { int loop; int prime = 1; for(loop = 2; loop < number; loop++) { if((number % loop) == 0) { prime = 0; } } if (prime ... Read More
273 Views
Following is the Java program which prints the kth prime factor of a number n, when k and n are given.Programimport java.util.Scanner; public class KthPrimeFactor { public static void main(String args[]) { int number, k, factor = 0; Scanner sc = new Scanner(System.in); System.out.println("Enter a number :"); number = sc.nextInt(); System.out.println("Enter the k value :"); k = sc.nextInt(); int temp = k-1; for(int i = 2; i< number; ... Read More
159 Views
The numbers which can be expressed as the sum of positive consecutive integers are known as polite numbers.Ex: 5 = 2+3The number of ways a number can be expressed as the sum of positive integers will be the Politeness of that number.Ex: 9 = 4+5 || 2+3+4AlgorithmGet the prime factors of a number.Get the powers of prime factors greater than 2.Add 1 to all of them.Multiply them, subtract 1 from the result.Programimport java.util.Scanner; public class PolitenessOfANumber { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter a number"); ... Read More
To Continue Learning Please Login
Login with Google