×

Equidigital in Java

In this section, we will understand what is an equidigital number and how to write Java programs to locate them. It is commonly asked in academic settings and Java coding interviews.

Equidigital Number

A number n is referred to as being equidigital if somehow the number of points inside the factorization for n (including powers) equals the digit count in n.

For instance, the number 32 is very much an equidigital number because it has a prime factorization of 24 and a total of two digits in its prime factorization (2 and 4), which is equivalent to the number of digits in 32. Another illustration would be the number 64. Their prime factorization is 27 and it contains a total of 2 digits (2 and 6), whereas the number has 3 digits. There exist Equidigital primes for all numbers. To print every Equidigital number up to a given number, n, is the challenge. The term "equidigital number" in Java refers to a natural number that, including exponents, includes the same sequence of numbers as the digits included in its prime factorization.

Steps for Finding Equidigital Numbers

Step-1: First, choose a natural number. Let's assume that it is n.

Step-2: Calculate the number n's prime factorization in step two. The exponents of prime factorization and the digits that make up its prime components should be kept in an array.

Step-3: Determine the array's size.

Step-4: Determine how many digits there are for the number n.

Step-5: A total number is now an equidigital number whereas if entire number of digits it contains equals that size of the array discovered in step-3; otherwise, it is not.

Note: Remember that 1 cannot be an equidigital number. simply because 1 does not constitute a prime number and can only be divided by itself.

Program for Equidigital Numbers in Java

The procedures outlined above are used in the following software to check for equidigital numbers.

Let the name of the file is EquidigitalNumberDemo.java

// a demo program that looks for an equidigital number between 1 and 30
import java.util.*;  
public class EquidigitalNumberDemo   
{  
// The procedure determines the exponents and numbers of the factors identified in // the prime factorization.
public static void addDigit(ArrList<Integer> sh, int num)  
{  
while(num != 0)  
{  
num = num / 10;  
sh.add(1);  
}  
}  
// a procedure for determining the all-prime factors of a given integer num, and for storing all 
// those factors in the list sh
public static void findThePrimeFactors(int num, ArrList<Integer> sh)  
{  
// Remove all of the 2s from the number and add them to the list.
Boolean flag = false;  
int count = 0;  
while (num % 2 == 0)   
{  
flag = true;  
num = num / 2;  
count = count + 1;  
}  
if(flag)  
{  
al.add(2);  
if(count > 1)  
{  
// manipulating the exponent digits
if(count > 9)  
{  
addDigit(sh, count);      
}  
else  
{  
sh.add(count);  
}  
}  
}  
// The number no must be odd after all of the 2s are subtracted from it. So, we can jump two spaces.
// Take note of the formula k = k + 2.
// Considering that 3 is odd and that 3 Plus 2 equals 5, which is also odd,
// It's also strange since 5 + 2 Equals 7, thus As a result, 
// we can observe that adding 2 to that of an odd number always results in an odd number.
for (int k = 3; k <= Math.sqrt(num); k = k + 2)   
{  
count = 0;  
flag = false;  
// While k divides the number no, store j and continue dividing the number no  
while (num % k == 0)   
{  
flag = true;  
num = num / k;  
count = count + 1;  
}  
if(flag)  
{  
// We must make sure that the primary elements 
// are not taken into account. 
// We must make sure that the components' 
// entire amount of digits is taken into account.
if(k > 10)  
{  
addDigit(sh, k);  
}  
else  
{  
sh.add(k);  
}  
if(count > 1)  
{  
// handling exponent digits
if(count > 9)  
{  
addDigit(sh, count);      
}  
else  
{  
sh.add(count);  
}  
}  
}  
}  
No should be added to the list when it's a 
// prime number with a value larger than 2.
if(num > 2)  
{  
if(num > 10)  
{  
addDigit(sh, num);  
}  
else  
{  
sh.add(num);  
}  
}  
}  
// a technique to determine the total 
// number of digits in the number num.
public static int findTheDigits(int num)  
{  
int digit = 0;  
while(num != 0)  
{  
num = num / 10;  
digit = digit + 1;  
}  
return digit;  
}  
// It is the main method  
public static void main(String args[])  
{  
// List used to store all a number's prime factors
ArrList<Integer> sh = new ArrList<Integer>();  
for(int s = 1; s <= 15; s++)  
{  
findThePrimeFactors(s, sh);  
int len = sh.len();  
int totalNoOfDigit = findDigits(s);  
if(len == totalNoOfDigit)  
{  
System.out.println(i + " is a number with equidigits.");      
}  
else  
{  
System.out.println(i + " is not equidigital in nature.");     
}  
sh.clear();  
}  
}  
}  

Output:

1 is not equidigital in nature.
2 is a number with equidigital.
3 is a number with equidigital.
4 is not equidigital in nature.
5 is a number with equidigital.
6 is not equidigital in nature.
7 is a number with equidigital.
8 is not equidigital in nature.
9 is not equidigital in nature.
10 is a number with equidigital.
11 is a number with equidigital.
12 is not equidigital in nature.
13 is a number with equidigital.
14 is a number with equidigital.
15 is a number with equidigital.

Related Topics

Round Robin Scheduling Program in Java

A CPU scheduling technique is known as Round Robin (RR). Additionally, network schedulers employ it. It was created specifically for a time-sharing system. The temporal slicing scheduling algorithm is another...

4 minutes read.

Calculator Program in Java

Calculator Program in Java A calculator performs the basic mathematical operations such as addition, subtraction, multiplication, etc. In this section, we will create a calculator program in Java using switch case...

5 minutes read.

Anagram Program in Java using String

Anagram Program in Java Anagrams are those words that are generated by rearrangement of the letters of another phrase or word. Usually, while doing the rearrangement, the original letters are used...

8 minutes read.

Vector in Java

Java Vector Class The Vector class is a legacy class that implements a growable array of objects. The components that it contains can be accessed using an integer index. The size of...

26 minutes read.

How to calculate time difference in Java

In this tutorial, we learned about how to calculate time differences in java language and which methods use to find the difference and its example. Prerequisite To understand this example, you need...

5 minutes read.

Ramanujan Number or Taxicab Number in Java

In this section, we will discuss what a Ramanujan number (also known as a Hardy-Ramanujan number) is and how to use a Java programme to determine if a given integer...

3 minutes read.

ArrayDeque in Java

ArrayDeque The ArrayDeque is one of the essential concepts in java to implement the deque interface. It will allow us to apply a resizable array to implement the Deque interface. This...

8 minutes read.

How to reverse a linked list in java

The process of reversing a linked list in Java will be covered in this section. One of the most common questions in interviews is about reversing a linked list. If...

11 minutes read.

Java Switch string

A multi-way branch statement is the switch statement. It offers a simple method for allocating execution to various code sections according to the expression's value. Primitive data types, including bytes,...

3 minutes read.

Collection Interfaces in Java with Examples

In this tutorial, we will discuss collection interfaces in Java with Examples. Introduction The Collection Interface is an individual from the Java Collections Framework. It is a root point of interaction of...

4 minutes read.

Sleeping Barber Problem in Java

The barbershop in this issue has one barber, one barber chair, and N chairs for customers in the waiting area. We may demonstrate the issue by keeping with the original...

6 minutes read.

Java String intern() method

Java String intern() method returns canonical representation for the String Object. syntax: public String intern() Return: It returns a interned String that to be a pool of unique String. Java String intern() Example 1 public class...

2 minutes read.

Session Tracking in Java

When a series of requests from the same User (i.e., requests coming from the same browser) occurs over an extended period of time, servlets employ a mechanism known as session...

3 minutes read.

Java Imageio

The javax.imageio package contains the final class known as Java ImageIO. For easy image reading, writing, and simple encoding and decoding, the class offers a convenient way. The class offers...

4 minutes read.

Java Beans

It is a Java class, It follows conventions they are: It must have a no-arg constructorIt must be serializable.It must provide the methods to get and set the properties Uses Of Java...

3 minutes read.

Java.lang.Exception.NoRunnableMethods

In Programming language, the java lang unexpected no precompiled methods error generally refers to a Junit exception that happens whenever Junit is incapable of locate the precompiled test methods. When...

4 minutes read.

Java Boolean logicalAnd() Method

The logicalAnd() method of Java Boolean class returns the result of implementing logicalAND operation on the specified Boolean operands. Syntax:public static boolean logicalAnd (boolean a, boolean b) Parameters:The parameters ‘a’ and ‘b’...

2 minutes read.

The final Keyword in Java

The final keyword is employed in several instances. Firstly, the non-access modifier final only applies to variables, methods, and classes. The final can be used in the following situations. Final Variables When...

6 minutes read.

Basic Terms in Multithreading

To understand the terms of multithreading, we must have knowledge about concurrency, processes, and threads. Concurrency The concurrency stands for performing multiple tasks at the same time. In the process communication, the operating system permits the process...

8 minutes read.

Java Program to find the smallest element in a tree

The variable min is used to store the data of the root, which is initially defined. The smallest node in the left subtree is then located by moving through the...

3 minutes read.