Page 204 - Computer science 868 Class 12
P. 204

17                  case 6: dayName = "Saturday"; break;
                18                  case 7: dayName = "Sunday"; break;

                19                  default: dayName = "Invalid day range";
                20              }
                21              System.out.println(day_number+ "  :  " +dayName);

                22          }

                23      }
              The output of the preceding program is as follows:
              Input number: 1

              1 : Monday




                Program 7     Write a program to accept a number and using switch case check whether the number is a
                              Palindrome number or a Niven number.
                              Palindrome Number: The reverse of the number is equal to the number.
                              Niven Number: A given number base is an integer that is divisible by the sum of its digits
                              when written in that base.

                1       import java.util.*;

                2       class palindrome_niven
                3       {

                4
                5           public static void main()

                6           {
                7               Scanner sc = new Scanner(System.in);

                8               int n, sum=0, temp, r;
                9               char ch;

                10              System.out.println("Enter a number " );
                11              n=sc.nextInt();

                12              System.out.println("Enter p/P for Palindrome / n/N for Niven");
                13              ch=sc.next().charAt(0);

                14              switch(ch)
                15              {
                16                  case 'p':

                17                  case 'P': temp=n;

                18                      while(temp>0)
                19                      {



                202202  Touchpad Computer Science-XII
   199   200   201   202   203   204   205   206   207   208   209