- 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 19 Articles for Java.Util Package
271 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
158 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
6K+ Views
Following is the Java program which prints all the divisors of a given number.Programimport java.util.Scanner; public class DivisorsOfNaturalNumber { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter required number :"); int num = sc.nextInt(); for(int i = 1; i
5K+ Views
If the sum of the digits of a number is divisible by 3, then the number is divisible by 3.Some examples of numbers divisible by 3 are as follows.The number 85203 is divisible by 3 because the sum of its digits (8 + 5 + 2 + 0 + 3 = 18) is divisible by 3.The number 79154 is not divisible by 3 because the sum of its digits (7 + 9 + 1 + 5 + 4 = 26) is not divisible by 3.Programimport java.util.Scanner; public class DivisibleBy3 { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter a number :"); String num = sc.nextLine(); int digitSum = 0; for(int i = 0; i
1K+ Views
A number is divisible by 11 if the difference between the sum of its alternative digits is divisible by 11.i.e. if (sum of odd digits) – ( sum of even digits) is 0 or divisible by 11 then the given number is divisible by 11.Programimport java.util.Scanner; public class DivisibleBy11 { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter a number :"); String num = sc.nextLine(); int digitSumEve = 0; int digitSumOdd = 0; for(int i = 0; i
787 Views
If the sum of the digits of a number is divisible by 9, then the number is divisible by 9.Some examples of numbers divisible by 9 are as follows. The number 51984 is divisible by 9 because the sum of its digits (5+ 1 + 9 + 8 + 4 = 27) is divisible by 9.The number 91403 is not divisible by 9 because the sum of its digits (9 + 1 + 4 + 0 + 3 = 17) is not divisible by 9.Programimport java.util.Scanner; public class DivisibleBy9 { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter a number :"); String num = sc.nextLine(); int digitSum = 0; for(int i = 0; i
2K+ Views
ProgramFollowing is the example to calculate the GCD of the numbers of an array.Live Demopublic class GCDOfArrayofNumbers{ public static int gcd(int a,int b){ int res = 0; while (b > 0){ int temp = b; b = a % b; a = temp; res = a; } return res; } public static void main(String arg[]){ int[] myArray = {3, 6, 8}; int result = gcd(myArray[0],myArray[1]); for(int i = 2; i < myArray.length; i++){ result = gcd(result, myArray[i]); } System.out.println("Gcd of n numbers is: "+result); } }OutputGCD of n numbers is: 1
690 Views
Following is an example which computes find LCM and GCD of two given numbers.Programimport java.util.Scanner; public class LCM_GCD { public static void lcm(int a, int b){ int max, step, lcm = 0; if(a > b){ max = step = a; } else{ max = step = b; } while(a!= 0) { if(max%a == 0 && max%b == 0) { lcm = max; break; } max += step; } System.out.println("LCM of given numbers is :: "+lcm); } public static void gcd(int a,int b){ int i, hcf = 0; for(i = 1; i
To Continue Learning Please Login
Login with Google