Page 219 - CA_Blue( J )_Class10
P. 219

c.  *                                          d.   ***
                           **                                             **
                           **                                             *
                    4.  Given the nested while loop below, what will be the value of treasuresFound after the loop finishes if totalFloors is 2 and
                        totalRooms is 3?
                       int totalFloors = 2;
                        int totalRooms = 3;
                        int floor = 1;
                        int treasuresFound = 0;
                        while (floor <= totalFloors) {
                            int room = 1;
                            while (room <= totalRooms) {
                                treasuresFound++;
                                room++;
                            }
                            floor++;
                        }
                        System.out.println("Total treasures found: " + treasuresFound);
                        a.  2                                          b.  3
                        c.  5                                          d.  6
                    5.  Each stall has 2 participants, and each participant presents 3 projects. How many times will the innermost loop execute in total?
                       for (int stall = 1; stall <= 3; stall++) {
                            int participant = 1;
                            while (participant <= 2) {
                                int project = 1;
                                do {
                                    System.out.println("Stall " + stall + ", Participant " + participant + ",
                        Project " + project);
                                    project++;
                                } while (project <= 3);
                                participant++;
                            }
                        }
                        a.  3                                          b.  6
                        c.  9                                          d.  18

                 B.  Answer the following questions:

                    1.  Write a program to input 10 numbers and print all the neon numbers.
                    2.  Write a program to input a number and print whether the number is a Magic Number or not. A Magic number is a number
                        whose eventual sum of the digits of the number is equal to 1.
                       For example, n = 28 = 2 + 8 = 10 = 1+ 0 = 1
                    3.  Write a program to print all the palindromic numbers between m and n (m<n). A palindromic number is a number whose reverse
                        of the digits is equal to the number.
                       For example, 121, 454, 66 etc.
                    4.  Write a program to “n” numbers and print the sum of all the Armstrong numbers.
                    5.  Write a program two numbers and print the whether it is a twin prime number or not. For example, say, 17,19 are twin primes
                        as the difference is 2 and both are prime numbers.







                                                                                                                       217
                                                                                                         Nested Loop   217
   214   215   216   217   218   219   220   221   222   223   224