-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJPQmagicNumber.java
More file actions
51 lines (51 loc) · 883 Bytes
/
Copy pathJPQmagicNumber.java
File metadata and controls
51 lines (51 loc) · 883 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
42
43
44
45
46
47
48
49
50
51
import java.util.Scanner;
public class JPQmagicNumber
{
public static int count=1, c=0;
public static int d,f,t;
public int noOfDigits(int d)
{
int n = d;
count = 1;
while((n=n/10)!=0)
{
count++;
}
System.out.println("Number of Digits "+count);
return count;
}
public int addDigits(int f)
{
int z=0;
while(f!=0)
{
int b = f/10;
c = f%10;
f = b;
z = z + c;
}
System.out.println("Sum of Digits "+z);
t = z;
return t;
}
public static void main(String[] qwe)
{
JPQmagicNumber obj = new JPQmagicNumber();
System.out.println("Enter the number");
int a = new Scanner(System.in).nextInt();
t = a;
while(t>9)
{
obj.noOfDigits(t);
obj.addDigits(t);
}
if(t==1)
{
System.out.println("The Number "+a+" is Magic Number");
}
else
{
System.out.println("The Number "+a+" is NOT a Magic Number");
}
}
}