Page 401 - Cs_withBlue_J_C11_Flipbook
P. 401
21 void ismagic()
22 {
23 int c = n; // making a copy of n
24 while(c>9) // upto 1 digit
25 {
26 c = Sum_of_digits(c);
27 // Sum of digits of the number is the new number
28 }
29 // display
30 if(c == 1)
31 System.out.println(n+" is a Magic number");
32 else
33 System.out.println(n+" is not a Magic number");
34 }
35
36 public static void main(int z)
37 {
38 Magic ob=new Magic();
39 ob.getnum(z);
40 ob.ismagic();
41 }
42 }
When you execute the preceding program, the Method Call dialog box appears:
The output of the preceding program is as follows:
172 is a Magic Number
205 is not a Magic Number
523 is a Magic Number
399
Recursion 399

