Page 202 - Computer science 868 Class 12
P. 202
The output of the preceding program is as follows:
OUTPUT 1
Enter a number to be checked:
5
101
OUTPUT 2
Enter a number to be checked:
8
1000
Program 5 Write the Java code with the following specifications.
class : Magic
Method()
int check_magic() : returns 1 if the number is magic else returns 0.
1 import java.util.*;
2 class Magic
3 {
4 int check_magic(int n)
5 {
6 int temp = n, rem, sum=0;
7 System.out.println(temp);
8 while(temp > 9)
9 {
10 while(temp > 0)
11 {
12 rem = temp % 10;
13 sum = sum + rem;
14 temp = temp / 10;
15 }
16 temp = sum;
17 sum = 0;
18 }
19 return temp;
20 }
200200 Touchpad Computer Science-XII

