A cyclic number is a number of "n" digits that when multiplied by 1, 2, 3,...n,
results in the same digits but in a different order. For example, the number 142,857
is a cyclic number since 142,857 x 2 = 285,714, 142,857 x 3 = 428,571, 142,857 x 4 = 571,428
and so on. It is not known just how many cyclic numbers exist.
import java.io.*;
public class Cyclic
{
public boolean Check(int a, int b)
{
String x = ""+a, y = ""+b;
int i, j , flag;
if(x.length()!=y.length())
return false;
for(i=0;i<x.length();i++)
{
flag = 0;
for(j=0;j<y.length();j++)
{
if(x.charAt(i)==y.charAt(j))
{
flag = 1;
break;
}
}
if(flag==0)
return false;
}
return true;
}
public static void main()throws IOException
{
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
int x, i, a, flag=0;
System.out.println("Enter a numberwa:");
x = Integer.parseInt(r.readLine());
Cyclic obj = new Cyclic();
for(i=2;i<=9;i++)
{
a = i*x;
if(obj.Check(x, a))
{
System.out.println(i+ "Cyclic Numbers: "+x+" & "+a);
flag=1;
}
}
if(flag==0)
System.out.println("No cyclic numbers found.");
}
}