×

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

How to take Array Input in Java

In this tutorial, we will learn about how to take array input in Java. So, before taking inputs let us know what an array is first. Array: An array is a collection...

10 minutes read.

Differences between Lock and Monitor in Java Concurrency

In this tutorial, we will discuss the overview of Lock and Monitor and the differences between them. Introduction Java Concurrency is the ability to perform specific tasks at a time parallelly. The...

4 minutes read.

Deadlock in Java

Deadlock is when two or more processes wait for the state to do their tasks, but none of them can do so. It is a very common problem that one...

6 minutes read.

Java Buffer Reader

When a variable cannot change its value during run time is called a Static way of programming. In this programming, a variable is directly assigned to a value. Program: Import java.io.*; class  A {  ...

4 minutes read.

Moran Numbers in Java

In this article, we will be acknowledged about the moran numbers in Java, how they are formed, what are the approaches to achieve the moran numbers. Moran Number A moran numbers are...

3 minutes read.

Object class in Java

In Java, a class is a file containing the Java byte code. It can essentially specifically be executed on the JVM (Java Virtual Machine), fairly significant. The JVM mostly generally...

6 minutes read.

How to Convert String to boolean in Java

How to Convert String to boolean in Java There are two methods to convert String to boolean: Using parseBoolean(string) method Using valueOf(string) method If the string contains "True," "true," or "TRUE,"...

3 minutes read.

Exception Handling Program in Java

Exception Handling Program in Java Exception means something that is abnormal. In Java, an exception is treated as a problem that disrupts the normal flow of the program. An exception leads...

7 minutes read.

Practical Number in Java

In this tutorial, we will understand what is meant by practical numbers. We will understand it throughthe aid of examples and implementation in a java programming language. The practical numbers...

5 minutes read.

Java String replace() method

Java String replace() method returns new String by replacing old characters with new characters or old CharSequence to new CharSequence. Syntax: public String replace(char oldChar, char newChar) public String replace(CharSequence target, CharSequence replacement) Parameters: oldChar...

2 minutes read.

The Diamond Operator in Java 7

The Diamond operator is a comparatively recent Java operator originally developed in JDK 7 to enhance type identification and eliminate boilerplate Java code. The Diamond operator is characterized by a...

2 minutes read.

Java Binary Operators

In this article, we are going to discuss about the binary operators in Java and their operations. Also, an example program will be discussed along with the operations. These are...

6 minutes read.

Prepared statement in Java

Prepared statement: A prepared statement is a statement that is pre-compiled SQL statement, and it is a sub-interface of a statement. Compared to other statement objects in java, Prepared Statement objects have...

3 minutes read.

Generic queue in Java

Before understanding how to implement a generic queue in java, one must know about generics and queue in java. Generics in Java Generics are parameterized types. The goal is to enable type...

6 minutes read.

How to compare dates in Java

Introduction: In Java, dates can be compared using a similar interface's compareTo() technique. This method returns 'zero' if each date is the same, returns a rate "more than 0" if...

6 minutes read.

Convert list to array Java

One of the popular collection interfaces for storing an ordered collection is the List. The List interface may contain repeating groups and preserves the insertion order of entries. This article will...

4 minutes read.

Vectors in Java

Vector Class We may make resizable arrays comparable to the ArrayList class using the Vector class, which implements the List interface. A vector is similar to a dynamic collection that can...

4 minutes read.

Java Location

PATH is an environmental variable that the system software now uses to find executable files (.exe) or Java binaries ( java or javac command). Once chosen, a route cannot be...

3 minutes read.

Difference between = = and equals ( ) in java

Java : Java is a pure object oriented language. It was introduced by James Gosling in the year 1995. The first public implementation of java was done by sun micro systems...

6 minutes read.

Java If Keyword

Definition: The if statement specifies a section of Java code that will run if an if statement's condition is false. The following conditional statements can be used in Java: To provide a block...

3 minutes read.