Page 454 - CA_Blue( J )_Class10
P. 454

INTERNAL ASSESSMENT





              Marks: 100




              [These programs are indicative only. Teachers and students should use their imagination to create innovative and
              original assignments.]


                   PROGRAMS ON USER-DEFINED METHODS

              (a)  Program depicting the concept of pure method.

                             Write a pure method boolean palindrome(int) which takes a value, checks whether it is a palindrome
                Program 1
                             number or not. If palindrome then return true else return false.


                 1      import java.util.*;

                 2      class palindrome_method
                 3      {

                 4          boolean palindrome(int n)           // Pure Method
                 5          {

                 6              int temp,rem,rev=0;           // Declaration of variable
                 7              temp=n;

                 8              while(temp>0)             // Digit extraction
                 9              {

                10                  rem=temp%10;
                11                  rev=rev*10+rem;

                12                  temp=temp/10;
                13              }

                14      // checking whether reverse of digit is same as original number
                15              if(rev==n)

                16                  return true;
                17              else

                18                  return false;
                19          }

                20          void main()
                21          {   Scanner sc= new Scanner(System.in);

                22              int num;


                452452  Touchpad Computer Applications-X
   449   450   451   452   453   454   455   456   457   458   459