-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab1_IN_Lab_1.java
More file actions
49 lines (46 loc) · 1.06 KB
/
Lab1_IN_Lab_1.java
File metadata and controls
49 lines (46 loc) · 1.06 KB
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
46
47
48
49
/* Problem Statement: Develop java code with 3 methods in myfirsyclass
a) Factorial()
b) isStrong()
*/
import java.util.Scanner;
public class Lab1_IN_Lab_1{
//method to find factorial which takes an integer x as argument and return long.
public static long factorial(int x)
{
long fact = 1;
while(x>0)
{
fact*=x;
x--;
}
return fact;
}
//method to find whether given number is strong or not which takes an integer x as argument and return boolean value.
public static boolean isStrong(int x)
{
int total = 0;
while(x>0)
{
total+= factorial(x%10);
x/=10;
}
return (total==x);
}
//Main method//
public static void main(String Args[])
{
int n;
System.out.println("Enter a number: ");
Scanner s = new Scanner(System.in);
n = s.nextInt();
System.out.println("Factorial of "+n+" = "+factorial(n));
if(isStrong(n))
{
System.out.println(n+" is Strong number");
}
else
{
System.out.println(n+" is not strong number");
}
}
}