Page 184 - CA_Blue( J )_Class10
P. 184

System.out.print("Enter a number : " );
                               m = sc.nextInt();
                               if(m==0)
                               break;
                               if(m%10==3)
                               s=s+m;
                               if(m%4==0)
                               p=p*m;
                               System.out.print("Do you want to continue:(y/n) ");
                               a = sc.next().charAt(0);
                               if(a=='Y' || a == 'y')
                                   cod = true;
                               else
                                   cod = false;
                          }
                    System.out.println("Sum of the number ending with 3 : " + s);
                    System.out.println("Product of the number that are multiples of 4 : " + p);
                    }
                    }
              D.  Assertion and Reasoning based questions.

                      The following questions consist of two statements – Assertion (A) and Reason (R). Answer these questions by selecting the
                    appropriate option given below:
                    a.  Both A and R are true, and R is the correct explanation of A.
                    b.  Both A and R are true, but R is not the correct explanation of A.
                    c.  A is true, but R is false.
                    d.  A is false, but R is true.
                  1.  Assertion (A): A "for" loop in Java is suitable for iterating a known number of times.
                     Reason (R): A "for" loop in Java explicitly specifies the initialization, condition, and increment/decrement in a single line.
                  2.  Assertion (A): A "while" loop is useful when the number of iterations is known beforehand.
                     Reason (R): A "while" loop in Java checks the condition before executing the loop body.
                  3.  Assertion (A): Using a "do-while" loop ensures that the loop body is executed at least once.
                     Reason (R):  In a "do-while" loop, a variable is used as increment or decrement.
                Ans.  1. a    2. d    3. b


                   Unsolved Questions



              A.  Tick ( ) the correct answer.
                  1.  Consider the following code:
                    int i, j;
                    for(i = 2, j = 4; i <= 4; i = i + 1)
                    {
                        if(j % i == 0)
                        break;
                    }
                    System.out.println(i);
                    What is the output of the above program snippet?
                    a.  2                                           b.  5
                    c.  1                                           d.  10
                  2.  Which of the following is not a loop in Java?
                    a.  for                                         b.  while
                    c.  do-while                                    d.  switch


                182182  Touchpad Computer Applications-X
   179   180   181   182   183   184   185   186   187   188   189