Occurrence of digit in cube of number in java



In this core java programming tutorial we will write a program to Find Occurrence of digit in number in java.


In this program we will find out factorial of number.


Let’s say cube of number(1551) is: 3731087151
Occurrence of 1 in cube of 1551 is: 3


Must read:Armstrong number in java.  

Full Program/SourceCode/Example in java to find Occurrence of digit in number in java >
/**
* @author AnkitMittal
* Copyright (c) 2015, AnkitMittal . All Contents are copyrighted and must not be reproduced in any form.
*/
public class OccurrenceOfNumberInCubeExample {
   public static void main(String[] args) {
         
          long num=1551;
          int occurrenceOf=1;  //calculate OccurrenceOf this digit in number.
         
          System.out.println("Cube of entered number("+num+") is: "+num*num*num );
          System.out.println("Occurrence of "+ occurrenceOf + " in cube of "+num+" is: "+calculateOccurrenceOf(num,occurrenceOf));
         
   }
  
   /**
   * method return OccurrenceOf digit in cube of given number.
   */
   public static int calculateOccurrenceOf(long num,int occurrenceOf){
          long cubeOfNumber=num*num*num;
          int count=0;
         
          while(cubeOfNumber>0){
                 if(cubeOfNumber%10==occurrenceOf){
                       count++;
                 }
                 cubeOfNumber=cubeOfNumber/10;
          }
          return count;
   }
}
/*OUTPUT
Cube of entered number(1551) is: 3731087151
Occurrence of 1 in cube of 1551 is: 3
*/


So in this core java programming tutorial we will write a program to Find Occurrence of digit in number in java.


 
 
/** Copyright (c), AnkitMittal www.JavaMadeSoEasy.com */


Previous program                                                                  Next program



Having any doubt? or you you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.


RELATED LINKS>

eEdit
Must read for you :