Page 223 - CA_Blue( J )_Class10
P. 223

else
                                                 System.out.print('*');
                                        }
                                        System.out.println();
                                    }
                                }
                            }
                        (b)  class Pattern2{
                                 public static void main(){
                                    int i,j;
                                     for(i = 1; i <= 5; i++){
                                       for(j = 5; j >= i; j--)
                                            System.out.print(j + " ");
                                       System.out.println();
                                    }
                                }
                            }
                    6.  Write a program to input a number and print whether the number is a special number or not.
                       (A number is said to be a special number if the sum of the factorial of the digits of the number is the same as the original
                        number).
                       Example: 145 is a special number, because 1! + 4! + 5! = 1 + 24 + 120 = 145.
                       (Where ! stands for factorial of the number and the factorial value of a number is the product of all integers from 1 to that
                        number, example 5! = 1 * 2 * 3 * 4 * 5 = 120)                                               [2012]
                   Ans.  import java.util.*;
                        class Special{
                            public static void main (){
                                 Scanner sc= new Scanner (System.in);
                                int n,sum=0,r,f,t,i;
                                 System.out.print("Enter a number: ");
                                n=sc.nextInt();
                                t=n;
                                while(t>0)
                                {   r= t % 10;
                                    f=1;
                                    for (i= 1; i<=r;i++)
                                    {f=f*i;
                                    }
                                    sum= sum + f;
                                    t=t/10;
                                }
                                if(n == sum)
                                     System.out.println(n+" is a special number.");
                                else
                                     System.out.println(n+" is not a special number.");
                            }
                        }





















                                                                                                                       221
                                                                                                         Nested Loop   221
   218   219   220   221   222   223   224   225   226   227   228