Skip to content

Commit 129aba5

Browse files
author
codehouseindia
authored
Merge pull request codehouseindia#144 from aditya-gite-04/master
Magic number program in JAVA
2 parents 0d0e6f3 + 43fd2ef commit 129aba5

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

Magic number

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import java.util.Scanner;
2+
3+
public class MagicNumber
4+
{
5+
public static void main(String[] args)
6+
{
7+
int n, r = 1, num, sum = 0;
8+
Scanner sc = new Scanner(System.in);
9+
System.out.print("Enter number=");
10+
n = sc.nextInt();
11+
num = n;
12+
while (num > 9)
13+
{
14+
while (num > 0)
15+
{
16+
r = num % 10;
17+
sum = sum + r;
18+
num = num / 10;
19+
}
20+
num = sum;
21+
sum = 0;
22+
}
23+
if (num == 1)
24+
{
25+
System.out.println("Magic Number");
26+
}
27+
else
28+
{
29+
System.out.println("Not Magic Number");
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)