-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYT18.java
More file actions
44 lines (37 loc) · 876 Bytes
/
YT18.java
File metadata and controls
44 lines (37 loc) · 876 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
/*Magic Number
* 325 = 3+2+5 = 10
* 10 = 1+0 = 1
* More Example: 226, 1234
*/
import java.io.*;
public class YT18
{
public static void main(String[] args)throws IOException
{
int n, r;
int s=0;
InputStreamReader I = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(I);
System.out.println("Enter the number which you want to check?: ");
n=Integer.parseInt(br.readLine());
while (n>9)
{
while(n>0)
{
r=n%10;
s=s+r;
n=n/10;
}
n=s;
s=0;
}
if(n==1)
{
System.out.println("Magic Number");
}
else
{
System.out.println("Not a Magic");
}
}
}