1 2 3 4 |
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. |

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
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."); } } |

firdosh ansari says

Write a program to add two numbers without using any arithmetic operator