-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPetersonNumber.java
More file actions
41 lines (30 loc) · 875 Bytes
/
Copy pathPetersonNumber.java
File metadata and controls
41 lines (30 loc) · 875 Bytes
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
import java.util.Scanner;
public class PetersonNumber{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a No. to check PetersonNumber : ");
int num = sc.nextInt();
int originalno = num;
int peterson = 0;
while(num>0)
{
int fact =1;
int rem = num%10;
for(int i = 1; i <=rem; i++)
{
fact = fact*i;
}
System.out.println("here " + fact);
peterson = peterson + fact;
num = num/10;
}
System.out.println("here " + num);
if(originalno == peterson)
{
System.out.println("PETERSON");
}else
{
System.out.println(" NOT PETERSON");
}
}
}