Program I:: Int N
Program I:: Int N
ALGORITHM:
public static void main(String [] args):
1. Start
2. Scanner object is created
3. object of the class Mystic is created
4. num is taken as input
5. if num<0(num is negative);
then, “Wrong input” is printed
Go to 10.
6. fillNum(num) method is called
7. if value returned by isMystic() method = true,
then, it is displayed as a mystic number
8. else, it is displayed as not a mystic number.
9. endif
10. end
public void fillNum(int num):
1. Start
2. The parameter num is assigned to the instance variable n
3. End
public boolean isMystic():
1. Start
2. boolean variable flag is initialized to false
3.if 3= value returned by the method sumOfDigits( ),
then, flag is set to true
4. value of flag is returned to calling method
5. End
public int sumOfDigits( ):
1. Start
2. copy is initialized to n and sum to 0.
3. if copy>0,
then repeat steps 4 to 5.
4. the last digit of copy is added to the previous sum.
5. the value of copy is divided by 10
6. go to 3
7. if sum >=10,
then repeat steps 8 to 10.
8. copy is initialized to sum and sum to 0.
9. repeat steps 3 to 6.
10. go to 7
11.the value of sum is returned.
12. End.