Write a program to check a number is Peterson number or not in java


 

Write a program to check a number is Peterson number or not in java

public class Peterson
{
   public static void main(String args[]){
     int num=145,temp,last,fact,sum=0;
     temp=num;
     
     while(temp!=0){
         last=temp%10;
         fact=1;
         for(int i=1;i<=last;i++){
            fact *= i;
            }
        sum+=fact;
        temp=temp/10;
        }
        
        if(num==sum){
        System.out.println(" Peterson Number");
        }else{
        System.out.println(" Not a Peterson Number");
        }
    
    }
}
Output
Peterson Number

Comments

Popular posts from this blog

How to make simple bill maker by using python tkinter

Make a GST Calculator using HTML and JavaScript

Write a program to find the sum of 1/2+4/3+5/6+8/7+9/10 using loop in java