Extravagant Number in JavaIn this section, we will learn what is extravagant number and also create Java programs to check if the given number is an extravagant number or not. The extravagant number Java program frequently asked in Java coding interviews and academics. Extravagant NumberA natural number that has fewer digits than the number of digits present in its prime factorization (including exponents) is known as the extravagant number. It is also known as the wasteful numbers because of this property. Extravagant numbers are the subset of composite numbers because one can factorize the extravagant numbers. But viceversa is not true. Steps to Find Extravagant Numbers Step 1: Pick a natural number. Let's say the number is n. Step 2: Compute the prime factorization of the number n. Store the digits involved in the prime factors of the prime factorization and its exponents in an array. Step 3: Find the size of the array. Step 4: Calculate the number of digits present in the number n. Step 5: If the total number of digits present in the number n is less than the size of the array found in step 3, then the number n is an extravagant number; otherwise, not. Examples of Extravagant Numbers
We see that for every number mentioned, the number of digits is less than the number of digits present in the prime factorization (including exponents). Hence, the numbers mentioned in the above table are extravagant numbers. Extravagant Numbers Java ProgramThe following program checks for extravagant numbers using the steps defined above. FileName: ExtravagantNumber.java Output: 1 is not an extravagant number. 2 is not an extravagant number. 3 is not an extravagant number. 4 is an extravagant number. 5 is not an extravagant number. 6 is an extravagant number. 7 is not an extravagant number. 8 is an extravagant number. 9 is an extravagant number. 10 is not an extravagant number. 11 is not an extravagant number. 12 is an extravagant number. 13 is not an extravagant number. 14 is not an extravagant number. 15 is not an extravagant number. 16 is not an extravagant number. 17 is not an extravagant number. 18 is an extravagant number. 19 is not an extravagant number. 20 is an extravagant number. 21 is not an extravagant number. 22 is an extravagant number. 23 is not an extravagant number. 24 is an extravagant number. 25 is not an extravagant number. 26 is an extravagant number. 27 is not an extravagant number. 28 is an extravagant number. 29 is not an extravagant number. 30 is an extravagant number.
Next TopicJava Unicode
