Get the list of Curious numbers in java.

What is Curious number?
Seriously, I just had come up with this name Curious because it got me curious while work on some project. The below method may have different name, but not aware of that name, so I myself name it as curious. So, let's jump into this method.
let us take number 9.

9x1=9        0+9=9
9x2=18      1+8=9
9x3=27      2+7=9
9x4=36      3+6=9
9x5=45      4+5=9
9x6=54      5+4=9
9x7=63      6+3=9
9x8=72      7+2=9
9x9=81      8+1=9
....
..
...



 import java.util.Scanner;  
 public class CuriousNumber{  
           public static void getCuriousNumberList(int value){  
           for(int j=1;j<=value;j++){  
                checkCuriousNumber(j);  
           }  
      }  
      //method to check entered number is cyclic or not  
      public static void checkCuriousNumber(int number){  
           int multiplier=0,sumOfMultiplier=0,sumOfEnteredNumber=0,count=0;  
           for(int i=1;i<=10;i++){  
                multiplier=number*i;  
                sumOfMultiplier=getSumOfDigits(multiplier);  
                sumOfEnteredNumber=getSumOfDigits(number);  
                if(sumOfMultiplier==sumOfEnteredNumber){  
                     count++;  
                }  
           }  
           if(count>=9){  //comment this section if you want to check the entered number is curious or not.  
                System.out.println(number);  
           }  
           /*if(count>=9){   //just uncomment this section and use this method in main() method, to check entered number is curious or not  
            * System.out.println("The entered number is curious");  
            * }  
            * else{  
            * System.out.println("The entered number is not curious");  
            * }  
            *   
            */  
           }  
      //method for adding digits  
      public static int getSumOfDigits(int number){  
           int remainder=0,holder=0;  
           do{  
                remainder=number%10;  
                number=number/10;  
                holder+=remainder;  
           }while(number>10);  
           return number+holder;  
      }  
      public static void main(String[] args) {    
           Scanner sc=new Scanner(System.in);  
           System.out.println("Enter the number");  
           int number=sc.nextInt();  
           //checkCuriousNumber(number); //uncomment this section to check entered number is curious or not.  
           getCuriousNumberList(number);  
           sc.close();  
 }  
 }  



Output:
Enter the number: 1000

9
18
45
90
99
180
198
297
396
450
477
495
549
594
639
693
729
738
792
819
891
900
909
918
927
936
945
990
999

Comments

Popular posts from this blog

Reasoning-Number Series

Reasoning-Letter Series

Profit and Loss